Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginner Problem python 2.7
#3
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
I am trying to help you, really, even if it doesn't always seem that way
Reply


Messages In This Thread
Beginner Problem python 2.7 - by Jonathan_levy - Jul-03-2018, 09:09 AM
RE: Beginner Problem python 2.7 - by buran - Jul-03-2018, 09:18 AM
RE: Beginner Problem python 2.7 - by gruntfutuk - Jul-03-2018, 11:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  small beginner problem FelixReiter 2 1,874 Nov-17-2020, 03:26 PM
Last Post: FelixReiter
  Beginner having Syntax Error problem RyanHo 3 2,391 Sep-10-2020, 08:33 AM
Last Post: cnull
  Beginner, my recursion returns None, and related problem zpacemanzpiff 2 1,818 Jul-02-2020, 04:25 AM
Last Post: zpacemanzpiff
  Beginner problem, replace function with for loop Motley_Cow 9 4,661 Sep-13-2019, 06:24 AM
Last Post: Motley_Cow
  Beginner problem in python script Cedmo 3 2,795 Jul-04-2019, 08:22 PM
Last Post: Cedmo
  Beginner Problem python 2.7 Jonathan_levy 2 2,697 Jul-04-2018, 08:46 PM
Last Post: ichabod801
  problem about 'if' and 'for' from a python beginner yzjnpu 3 3,074 Jun-26-2018, 03:47 PM
Last Post: buran
  Beginner. Calculator problem ¯\_(ツ)_/¯ stykus1992 0 2,361 Feb-15-2018, 11:01 AM
Last Post: stykus1992

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020