Apr-23-2017, 06:15 PM
What version of Python are you using? What are you providing when input() asks for two numbers?
It looks like you're using Python 3, and I'll imagine an input like so
It looks like you're using Python 3, and I'll imagine an input like so
Output:>>> a, b = input("> ")
> 1 2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: too many values to unpack (expected 2)
Recall that input() gives you a string, so the way the code works is much like thisOutput:>>> a, b = "1 2"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: too many values to unpack (expected 2)
Python isn't trying to interpret the contents of the string as integers here.Output:>>> a, b = "12"
>>> a
'1'
>>> b
'2'
What you could do is get the string from input(), use str.split (based on whether you want to use whitespace, commas, or whatever) and then use a comprehension on that split string to turn the contents into ints, or floats.