Mohammad Khan
Mohammad Khan

Reputation: 11

Program that prompts user for any number of readings and terminates by entering a value that is not a number

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

Answers (2)

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

Georgina Skibinski
Georgina Skibinski

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

Related Questions