1st one is ok. but in second one it showed:ValueError: invalid literal for int() with base 10: 'done'
count = 0
total = 0
while True :
inp =input('enter number : ')
if inp == 'done': break
value = float(inp)
count = count 1
total = total value
print(count)
print(total)
print(total/count)
2nd :
count = 0
total = 0
while True :
inp =int(input('enter number : '))
if inp == 'done': break
count = count 1
total = total inp
print(count)
print(total)
print(total/count)
CodePudding user response:
Right here
inp =int(input('enter number : '))
You are casting your input to int. So when you type 'done' to console, you get error, because it's not a valid integer
CodePudding user response:
int('done') isn't a integer. So the int() function returns an exception.
CodePudding user response:
inp is an integer. Therefore, you can't ask whether it's equal to a string('done'), because you're comparing different things.
