Python Forum

Full Version: instruction refused on a "while loop"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
1. assign user input to variable (str)
2. check the user input. if it is THAT specific value you want to use for quit - then use break to exit the loop
3. if it is not p.2 - convert to number and calculate
4. Also why you set size = 40 and never use it. think what condition should you use in the while statement.
Here is the solution of my problem using error handling. I hope the code will be tagged. Here is the code:::::::::::::::::::::::::::
file5.py
size = 40
print("here is the addition of many numbers (even with a .) Maximum of numbers=", size)
print("Once you have finished your list of numbers, just press $ to indicate the end\n")
total = 0.0
value = 0.0
count = 1
while (count != 0):
    try:
        value = float(input("enter the value: "))
    except ValueError:
            count=count-1
            average = total/count
            print("average value= ", average)
            exit()
    else:
        print(value)
        print(total)
        total = value + total
        print(total)
        count = count + 1
Pages: 1 2