-1
name = ''
while name != 'your name':
    print('Please type your name.')
    name = input()
print('Thank you!')

When I input 'your name' or whatever, it doesn't work. I used the Automate the Boring Stuff with Python.

(Error message: Traceback (most recent call last):
  File "C:\Users\CSA\Desktop\superami.py", line 4, in <module>
    name = input()
  File "<string>", line 1, in <module>
NameError: name 'j' is not defined)
Avunz
  • 1
  • 1

2 Answers2

0

This will work in python 2

name = ''
while name != 'your name':
    print('Please type your name.')
    name = raw_input()
print('Thank you!')
Lucas Wieloch
  • 818
  • 7
  • 19
0

It looks like you're using Python 2, where input will evaluate the string provided by the user.

You should either:

  • Use Python 3. Python 2 is EOL in 2020.
  • Use raw_input
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328