Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
defination problem
#1
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)
Reply
#2
== 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))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020