+ 1
Whatâs the difference? - Do The Math
sum = 0 while True: x = input() sum += int(x) if x == "stop": break print(sum) & sum = 0 while True: x = input() if x == "stop": break sum += int(x) print(sum) I wonder whatâs the difference between these two coding? The first doesnât work but second does, they seem similar to me!
2 Answers
+ 8
The first will give you an error if the user enters stop since you're attempting to convert 'stop' to an int. The second will instead check if the user has entered stop and will exit the loop prior to attempting the conversion. It will still error though if a value other that 'stop' or an integer is entered by the user.
+ 3
I see! Got it! Thanks! ChaoticDawg