[Tutor] decimal input problem

Alan Gauld alan.gauld at btinternet.com
Tue Dec 21 11:05:29 CET 2010


"jtl999" <jacksmoo111 at gmail.com> wrote

> when I try to multiply with a decimal  number in python with the 
> input
> this is what i get
>
> Enter first number: 1.2
> Traceback (most recent call last):
>  File "Timesed.py", line 18, in <module>
>    numberx1 = (int)(raw_input('Enter first number: '))
> ValueError: invalid literal for int() with base 10: '1.2'

You are inputting a floating point number - 1.2 and
trying to convert it to an integer. You need to convert
raw_input to a float() rather than an int()

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list