Python Forum
Beginner Problem python 2.7 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Beginner Problem python 2.7 (/thread-11321.html)



Beginner Problem python 2.7 - Jonathan_levy - Jul-03-2018

. im trying to learn python and i did a code , it gave me an error and i dont under stand why
[Image: z2lncmdyrtmz.png]



[Image: ywwcmixzuntz.jpg]


RE: Beginner Problem python 2.7 - buran - Jul-03-2018

Please, don't post images. Copy/paste your code in python tags. Copy/paste full traceback in error tags. See BBCode help for more info.


RE: Beginner Problem python 2.7 - gruntfutuk - Jul-03-2018

Firstly, I'd strongly advise you, as a beginner, to learn Python 3 rather than Python 2.7.

Python 3 has been around for over 10 years, and Python 2.7, the last official version of Python 2, will stop being supported (or fixed) on Jan 1, 2020.

If you are going to continue to use python 2.7, you should know that using the input() function is a bad thing. A malicious user could enter code and do things to your computer you might not be happy with.

In Python 2.7, use raw_input() instead of input().

(In python 3, the original input() function was dropped and raw_input() was renamed input() ).

The reason your programme failed when you entered your name, was Python 2.7 tried to evaluate what you entered and didn't recognise anything named ds.

Instead, use raw_input() which returns a string.

Use this for the age input as well BUT because you will get a string instead of a number, you need to convert the string to an integer BEFORE you attempt to use it in a calculation. For example:

num1 = raw_input('Enter first number: ')
num2 = raw_input('Enter second number: ')
total = int(num1) + int(num2)
print 'Total is:', total