[Tutor] Startup Python
Alan Gauld
alan.gauld at yahoo.co.uk
Wed Apr 12 13:41:30 EDT 2017
On 12/04/17 13:47, Wim Berrelkamp wrote:
>>>> a=2
Here you assign the number 2 to 'a'
>>>> d=a+4
>>>> print(d)
> 6
> a=input('-->' )
Here you assign whatever character(s) the user types to 'a'.
The fact that it looks like 2 doesn't change the fact that it
is really the character '2'. So you need to convert it to
a number using either int() or float()
a = int(input('-->'))
or
a = float(input('-->'))
> print(a)
> d=a+4
> print(d)
>
> I tried to use float(), but nothing works.
> What am I doing wrong ?
I don't know, because you don't show us how you tried to
use float(), but if you apply it as shown above it
should work.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list