Python Forum

Full Version: defination problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
having problem with defining total
#user chooses 5 numbers and program totals them
num= int(input ('choose your 1st num:'))
plus=1
while plus < 6:
    num = int(input ('Choose ur next no.'))
    total == total + num
    plus += 1
print ('The total sum :', total)
== is comparison (check for equality)
you want =
also total is not initialized, so you will get NameError
Error:
Traceback (most recent call last): File "***", line 6, in <module> total = total + num NameError: name 'total' is not defined >>>
also, instead of using while, you can use for loop and simplify the code
#user chooses 5 numbers and program totals them
total = 0
for i in range(6):
    num = int(input ('Choose your next no.'))
    total = total + num
print ('The total sum: {}'.format(total))