[Tutor] Problem with "input" in Python 3

Kent Johnson kent37 at tds.net
Mon Feb 15 14:09:26 CET 2010

```On Mon, Feb 15, 2010 at 7:34 AM, pja <peterjohnanderson at gmail.com> wrote:

> 05 import math
> 06
> 07 def main():
> 08 print("This program finds the real solutions to a quadratic\n")
> 09
> 10 a, b, c = input("Please enter the coefficients (a, b, c): ")
> 11
> 12 '''
> 13 a = int(input("Please enter the first coefficient: "))
> 14 b = int(input("Please enter the second coefficient: "))
> 15 c = int(input("Please enter the third coefficient: "))
> 16 '''
> 17
> 18 discrim = b * b - 4 * a * c
> 19 ...
>
> 25 main()
>
> Lines 08 to 12 are my Python 3 working solution but line 06 does not work in
> Python 3. When it runs it produces:
>
> Please enter the coefficients (a, b, c): 1,2,3
> Traceback (most recent call last):
> File "C:\Program Files\Wing IDE 101 3.2\src\debug\tserver\_sandbox.py", line
> 25, in <module>
> File "C:\Program Files\Wing IDE 101 3.2\src\debug\tserver\_sandbox.py", line
> 10, in main
> builtins.ValueError: too many values to unpack
>>>>
>
> Clearly the problem lies in the input statement. If I comment out line 10
> and remove the comments at lines 12 and 16 then the program runs perfectly.
> However, I feel this is a clumsy solution.
>
> Could somebody please guide me on the correct use of "input" for multiple
> values.

Python 3 input() is the same as Python 2 raw_input() - the result is a
string. You could use
a, b, c = ast.literal_eval(input("Please enter the coefficients (a, b, c): "))

Kent
```