Traceback (most recent call last): File "/piston/jobs/574143c7-995f-44a0-a56c-d26a7cb37e64/test.py", line 12, in <module> Cal(calories) File "/piston/jobs/574143c7-995f-44a0-a56c-d26a7cb37e64/test.py", line 3, in Cal calories[key]=int(calories[key])ValueError: invalid literal for int() with base 10: 'Day1'
Question
Traceback (most recent call last): File "/piston/jobs/574143c7-995f-44a0-a56c-d26a7cb37e64/test.py", line 12, in <module> Cal(calories) File "/piston/jobs/574143c7-995f-44a0-a56c-d26a7cb37e64/test.py", line 3, in Cal calories[key]=int(calories[key])ValueError: invalid literal for int() with base 10: 'Day1'
Solution
It seems like you're trying to convert a string to an integer, but the string is 'Day1' which can't be converted to an integer.
Here's a step-by-step explanation of the error:
- You have a dictionary called
calories. - You're trying to iterate over this dictionary with a key.
- For each key, you're trying to convert the corresponding value to an integer using
int(). - However, one of the values in your dictionary is 'Day1', which is a string that can't be converted to an integer.
- This is causing a
ValueError.
To fix this, you need to ensure that all values in your calories dictionary are numbers (or strings that can be converted to numbers) before trying to convert them to integers.
Similar Questions
Traceback (most recent call last): File "/piston/jobs/53e579ec-e171-4af1-bede-9cad6fa7f966/test.py", line 9, in <module> calories_burned=int(input())ValueError: invalid literal for int() with base 10: 'Day1'
Traceback (most recent call last): File "/piston/jobs/39b97eff-97e6-4228-b7d8-6145197c2aa3/test.py", line 10, in <module> Cal(calories) File "/piston/jobs/39b97eff-97e6-4228-b7d8-6145197c2aa3/test.py", line 2, in Cal avg=sum(calories.values())/len(calories)TypeError: unsupported operand type(s) for +: 'int' and 'str'
Traceback (most recent call last): File "/piston/jobs/0b735acd-420a-4c07-ba63-ca0647f9d8e7/test.py", line 16, in <module> n=int(input())ValueError: invalid literal for int() with base 10: '24 2'
24 23Traceback (most recent call last): File "/piston/jobs/09281298-42ab-4850-b2da-e6fc4d5a0ea3/test.py", line 9, in <module> hrs=D//pTypeError: unsupported operand type(s) for //: 'int' and 'function'36 32Traceback (most recent call last): File "/piston/jobs/5da139ac-bf93-4331-8eb2-a96e6fe8883a/test.py", line 9, in <module> hrs=D//pTypeError: unsupported operand type(s) for //: 'int' and 'function'
Traceback (most recent call last): File "/piston/jobs/e6a89de3-48e6-4609-8f0f-b250f44c7ea7/test.py", line 26, in <module> r=insert(r,val) File "/piston/jobs/e6a89de3-48e6-4609-8f0f-b250f44c7ea7/test.py", line 10, in insert if root.val<key:AttributeError: 'int' object has no attribute 'val'
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.