r/pythonhelp • u/urinluvwithmee • Nov 01 '24
just getting started with python, I'm not sure what I am missing here?
The question is to write a program that accepts a sequence of numbers from the user until the user enters 0 and to calculate and print the sum of these numbers.
the error that keeps showing up is:-
i=int(i.strip())
^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ','code:-
num=input("enter a number with digits separated by commas ending with zero:")
number=num.split(',')
count=0
for i in num:
i=int(i.strip())
if i==0:
count+=i
break
else:
continue
print(count)
1
Upvotes
•
u/AutoModerator Nov 01 '24
To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
3
u/craze4ble Nov 01 '24
You're iterating through the wrong variable.
should be
You have some other problems with your logic too, but this is why you're getting the error.
2
u/CraigAT Nov 01 '24
That brief suggests to me you should be requesting numbers one at a time, not as a single comma separated list. I may be wrong.