[Tutor] Fwd: Startup Python
Wim Berrelkamp
wimberrelkamp at gmail.com
Fri Apr 14 01:37:50 EDT 2017
Dear Alan Gauld,
Pure by coïncedent I found your answer to me on the internet at
http://code.activestate.com/lists/python-tutor/109848/
There was no answer on my e-mail account.
Your answer works !
Thanks for that !
Regards,
Wim Berrelkamp
Groningen, The Netherlands
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
---------- Forwarded message ----------
From: Wim Berrelkamp <wimberrelkamp at gmail.com>
Date: 2017-04-12 14:47 GMT+02:00
Subject: Startup Python
To: tutor at python.org
Dear Tutor,
In earlier days I programmed a lot with Quick Basic in DOS.
Now I retiered, I hoped to have Python as a platform.
So I installed it and saw a lot of simmularity with Basic.
I hope you can help me with the following, which should not be difficult,
but I cannot find the solution.
When I type this:
>>> a=2
>>> d=a+4
>>> print(d)
6
I got the correct answer.
When I try this to run it in a Module:
a=input('-->' )
print(a)
d=a+4
print(d)
I get this as a result:
input test.py
-->2
2
Traceback (most recent call last):
File "C:\Users\Gebruiker\AppData\Local\Programs\Python\Python36\Lib\idlelib\input
test.py", line 3, in <module>
d=a+4
TypeError: must be str, not int
>>>
I receive this message.
I tried to use float(), but nothing works.
What am I doing wrong ?
Thanks in advance !
Regards,
Wim Berrelkamp
Groningen, The Netherlands
More information about the Tutor
mailing list