1

I was trying to get some input in python and I have no idea what is my problem

 name = input("What's your name?")
age = int(input("How old are you?"))
year = str((100 - age) + 2018)
print("Hello "+ name + ",in " + year + "you'll be 100 y.o")

and when I use my name as input like "shayan", thats came out:

name = input("What's your name? ")
File "<string>", line 1, in <module>
NameError: name 'shayan' is not defined

I tri my code in "atom" , "sublime" , "visual studio code"

  • Please post the full code. The part of code in the above question isn't indicating the line where the error was encountered. – waqasgard Dec 09 '18 at 08:24
  • Atom, Sublime and VS Code are text editors. They make no difference to how the program runs. – JJJ Dec 09 '18 at 08:36

1 Answers1

0

It's because you're on python 2, so input in python is basically eval(input(...)) in python 3, so it will take inputs as code, not strings, so gotta use raw_input in python 2:

name = raw_input("What's your name?")
age = input("How old are you?")
year = str((100 - age) + 2018)
print("Hello "+ name + ",in " + year + "you'll be 100 y.o")
U13-Forward
  • 69,221
  • 14
  • 89
  • 114