I'm new in coding and recently I've been practicing Python to use in a script in uni lab. Basically I'm trying to do a loop over a input loop it self. See:
U_Ant = []
while True:
Sample_ID = input("Sample ID: >>" )
print('Assign the halo diameter according to the previous order, then type "done" when finished')
Ant_Halo = input(">", )
if Ant_Halo == 'done':
break
try:
fAnt_Halo = float(Ant_Halo)
except:
print('Invalid input')
continue
try:
U_Ant.append(int(Ant_Halo))
except:
U_Ant.append(float(Ant_Halo))
But the real thing starts right after that. This single code above allows user to input values for only one sample (halo diameter given to a specific sample), what I want to do is:
print("All fields are correct?")
check_1 = input("Y/N: >")
if check_1 == "Y" or 'y':
pass
else:
return self.mo_antimicrobial()
print("Do you wish to add more samples?")
check_1
if check_1 == "Y" or 'y':
return self.mo_antimicrobial()
else:
pass
And be able to add more samples and inputs without fearing lose them. The point of the whole script is to gather multiple sample data (halo diameters) and plot as a table (where the columns are variable as well), so I must have a way to make every entry unique.
I tried to use dictionaries but I'm not being able to neither add int or str to it. I though of using:
def pilot():
sample_number = int(input("Please, set the number of samples for this experiment:" ))
for i in range(0, sample_number):
while True:
U_Ant = []
Sample_ID = input("Sample ID: >>" )
print('Assign the halo diameter according to the previous order, then type "done" when finished')
Ant_Halo = input(">", )
if Ant_Halo == 'done':
break
try:
fAnt_Halo = float(Ant_Halo)
except:
print('Invalid input')
continue
try:
U_Ant.append(int(Ant_Halo))
except:
U_Ant.append(float(Ant_Halo))
cache_data += {'ID': [Sample_ID], 'Halo': [U_Ant]}
print("Do you wish to add more samples?")
check_1 = input()
if check_1 == "Y" or 'y':
pilot()
else:
pass
but things won't work, since the output is just:
Sample_ID = input("Sample ID: >>" )
print('Assign the halo diameter according to the previous order, then type "done" when finished')
Ant_Halo = input(">", )
Sorry If I was too much vague, it's my first time posting on stack and this is also a reflex of my ignorance in this programming language. Thanks in advance.