python - Loop that uses try/except for input and loops until 'done' is entered -
I'm new to coding in Python and I'm trying to write a loop that asks for numerical input and By the time the user input "done", he exits from the loop and prints the variable: number, count and average. (Not trying to store anything in a list)
I also want to print "invalid input" and if the user enters anything then he will continue the loop when Unless it is "full",
Unfortunately this gives "invalid input" and whenever I enter "done" it keeps looping even though what I am doing wrong? Can anyone tell me in the right direction?
number = 0 count = 0 average = 0 inp = 0 while correct: try: inp = int (raw_input ('enter a number:')) If 'ip' is done Print: 'Invalid Input' Print Number Print Number Print Float (average)
: Number = number + RAP number = count + 1 average = float (number / count):
sum = 0.0 count = 0 while true: inp = raw_input ('Enter a number:') If inp == 'done' : Try to break: sum + = int (inp) count = = 1 except for ValueError: Count 'illegal input' print amount print count if count! = 0: # Zero print zodiac / avoid division by counting
Comments
Post a Comment