Python Forum
ValueError: invalid literal for int() with base 10: '2 5'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ValueError: invalid literal for int() with base 10: '2 5'
#1
In hackerrank, i got a question named average function.
i gave my code like this
def avg(nums):
    mean = (a + b) / 2
    return format(mean, '.2f')
print(avg(int(input())))
it is showing error like this
Error:
ValueError: invalid literal for int() with base 10: '2 5'
Reply
#2
'2 5' is not a valid input that can be turned into an int, you would need to split the string and then turn the split items into int
Reply
#3
How did OP manage to post here?
Quote:Any user with 50+ posts in the user group "Privileged User" or higher may read/write to this forum. This forum is invisible to everyone else.
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#4
(Jun-13-2020, 09:25 AM)pyzyx3qwerty Wrote: How did OP manage to post here?

I moved the thread to the wrong homework section, fixed it now. thanks.
Reply


Forum Jump:

User Panel Messages

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