I run the code and fill in but my text file does not have the data
my code:
def register_patient():
vaccinecenter = input("Your vaccine location in VC1 or VC2?").upper()
while vaccinecenter != "VC1" and vaccinecenter !="VC2":
print("Please only insert VC1 or VC2")
vaccinecenter = input("Your vaccine location in VC1 or VC2?").upper()
patientname = name()
patient_id = patientid()
age,vaccine= checkageformvaccine()
phonenumber=contact_number()
medicalhistory = patient_information()
patientdetail = [patientname, patient_id, age , phonenumber,medicalhistory,vaccine, vaccinecenter]
patientlist=[]
with open("patient record.txt","a"):
for counter in range(0):
patientlist = []
dt = input("patient_id: ")
dn = input("age: ")
fc = input("vaccine center")
patientlist.append(dt)
patientlist.append(dn)
patientlist.append(fc)
print(",".join(str))
patientlist.append(patientdetail)
print("Record Added Succesfully.")
print("Redirect to menupage")
menupage()
how to fix it?? the output data should have written in text
CodePudding user response:
I'm rather sure, your problem is the
for counter in range(0):
You are iterating from 0 to 0 exclusive. Therefore, the loop will not be executed and thus, no content written to the file.
So you should either remove this loop at all, or, if you want it to be executed multiple times, change the value given to range
with something other than 0.
CodePudding user response:
Im not really sure what content you want to write and in what fashion. But have a sample snippet below.
def register_patient():
vaccinecenter = input("Your vaccine location in VC1 or VC2?").upper()
while vaccinecenter != "VC1" and vaccinecenter !="VC2":
print("Please only insert VC1 or VC2")
vaccinecenter = input("Your vaccine location in VC1 or VC2?").upper()
patientname = name()
patient_id = patientid()
age,vaccine= checkageformvaccine()
phonenumber=contact_number()
medicalhistory = patient_information()
patientdetail = [patientname, patient_id, age , phonenumber,medicalhistory,vaccine, vaccinecenter]
patientlist=[]
with open("patient record.txt","a") as fp:
for counter in range(0):
patientlist = []
dt = input("patient_id: ")
dn = input("age: ")
fc = input("vaccine center")
patientlist.append(dt)
patientlist.append(dn)
patientlist.append(fc)
fp.write(str(dt))
fp.write(str(dn))
fp.write(str(fc))
print(",".join(str))
patientlist.append(patientdetail)
print("Record Added Successfully.")
print("Redirect to menupage")