1

In this tutorial I'm following this program that asks the user for their name, and then responds with hi" + name. I followed the instructions but it isn't accepting inputs. Is the tutorial wrong/outdated?

print ("Hi! I’m Joseph. What's your name?")
name = input()
print ("Hi" + name)

It’s supposed to respond with a literal Hi and then the name but instead I am shown this:

Traceback (most recent call last):
  File "C:/Users/user/Documents/AA school/ICT/python/Using str variables.py", line 2, in <module>
    name = input()
  File "<string>", line 1, in <module>
NameError: name 'Adam' is not defined

I've tried changing the + name to + str(name), and putting spaces in and removing them from different areas of the code.

What’s wrong?

Eb946207
  • 748
  • 8
  • 26
A.Nixon
  • 11
  • 1
  • 2
    You are the one with the outdated Python version. ;) Switch to Python3 or use `raw_input`. – timgeb Dec 26 '18 at 21:19
  • 1
    Unrelated to the problem: You should put the prompt as an argument to `input()` or `raw_input()` rather than printing it separately. – Barmar Dec 26 '18 at 21:21
  • 1
    @DanFarrell Why do you think that? It's the expected error with Python 2.x. – Barmar Dec 26 '18 at 21:22
  • 2
    lol, because I'm dumb :P . always forget `input()` is an eval-like operation in 2.x – erik258 Dec 26 '18 at 21:23
  • change the second line to `name = raw_input()` and add a space in the third line right after hi (so `"hi "`). `input()` is what you use in python 3.x. The equivalent in python 2.7 is `raw_input()`. – Niels Henkens Dec 26 '18 at 21:36

0 Answers0