0

In the "Learn Python the hard way" book in exercise 11 I found something like this:

print "How old are you?",  
age = raw_input()

And the output is:

How old are you? 38

But when I add the comma in Python 2.7.13 it just prints the print statement and a new line begins.

cs95
  • 379,657
  • 97
  • 704
  • 746
  • I just dont know how to do it?plz help. – Mehedi Mondal Jul 01 '17 at 20:39
  • Possible duplicate of [How to print without newline or space?](https://stackoverflow.com/questions/493386/how-to-print-without-newline-or-space) – gawi Jul 01 '17 at 20:42
  • Possible duplicate of [Execute Commands Sequentially in Python](https://stackoverflow.com/questions/359347/execute-commands-sequentially-in-python) – Aakash Verma Jul 01 '17 at 20:43
  • No its not.Just look at that a variable is created without ending of a print line with comma. – Mehedi Mondal Jul 01 '17 at 20:47
  • Hi Mehedi, welcome to SO. Please try to format your questions properly and have a look here: https://stackoverflow.com/help/how-to-ask – petezurich Jul 01 '17 at 20:57

2 Answers2

0

It's a script where you need to have this code, not in the interactive console.

That is preferrably. If you still want to run it on the console, read here since I don't wanna copy and reword :D

Aakash Verma
  • 3,705
  • 5
  • 29
  • 66
0

If you run your script, your console will print the line:

How old are you?

You can than enter your age into the console ('38'), and your age is than saved into the variable 'age'. Try entering your age in the console and than printing 'age'.

Or try something like this:

print "How old are you?",  
age = raw_input()

print ("I am " + age + " years old.")
Niels Henkens
  • 2,553
  • 1
  • 12
  • 27
  • Yeah,i was able to do that.I thought that i can creat that age variable within the print statement maybe that impossible. – Mehedi Mondal Jul 02 '17 at 02:42
  • I don't really understand what you mean with "I thought that i can create that age variable within the print statement..". I looked up this specific question from the book you mentioned and I don't think they tell you very clear what should happen. When you run the script, Python will print "How old are you?" and then you are suppose to type in '38' (followed by the height and weight). At the end of the exercise it will then print out "So, you're '38' old, '6\'2"' tall and '180lbs' heavy." – Niels Henkens Jul 03 '17 at 15:08
  • ooh i see.thnx for the help – Mehedi Mondal Jul 03 '17 at 15:38