Reputation: 11
Program in python that prompts the user to enter number of readings (including none) terminating their list by entering any value that is not a number
Upvotes: 1
Views: 43
Reputation: 460
This code loop will only stop if the string
cannot be converted to float
while True:
x = input('Enter a number: ')
if x != '':
try:
float(x)
except:
break
Upvotes: 1
Reputation: 13397
Try:
x=[]
x.append(input("please insert a number... "))
while((x[len(x)-1].isnumeric()) or (len(x[len(x)-1])==0)):
x.append(input("please insert a number... "))
del x[-1]
print(x)
Upvotes: 1