1

I run this code on PyCharm 2.7 and each time I enter an input as a name I get this error:

Traceback (most recent call last):
  File "C:/Users/Korisnik/PycharmProjects/untitled/Program test.py", line 4, in <module>
    character_name = input("Select a name for your character: ")
  File "<string>", line 1, in <module>
NameError: name 'aaa' is not defined

Process finished with exit code 1

Is there any way to fix this? I am a beginner in python scripting so an explanation on how to fix this would be great.

This is my code:


print("-- Story generator by Mateo Primorac --")

character_name = input("Select a name for your character: ")
character_age = input("Select the age for your character: ")
character_gender = input("Select a gender for your character: ")
character_color = input("Select your characters favorite color: ")

if character_gender == "male" or "Male":
    print("There was once a man called " + character_name + ",")
    print("He is " + character_age + " years old.")
    print("He likes wearing " + character_color + " shirts and pants because that is his favorite color.")
    print("Press space or enter to exit.")
    input()
    quit()

if character_gender == "female" or "Female":
    print("There was once a woman called " + character_name + ",")
    print("She is " + character_age + " years old.")
    print("She likes wearing " + character_color + " shirts and dresses because that is her favorite color.")
    print("Press space or enter to exit.")
    input()
    quit()
MaxD
  • 17
  • 7
  • You're writing your code like it's Python 3, but running it on Python 2. – user2357112 Jun 16 '20 at 11:26
  • 2
    Does this answer your question? [input() error - NameError: name '...' is not defined](https://stackoverflow.com/questions/21122540/input-error-nameerror-name-is-not-defined) – SiHa Jun 16 '20 at 11:29
  • My question is answered by LeopardShark. – MaxD Jun 16 '20 at 11:31

3 Answers3

0

If this is Python 2, you need to use raw_input instead of input. (Or switch to Python 3)

LeopardShark
  • 3,820
  • 2
  • 19
  • 33
0

Change the "OR" to "AND" and run in python 3

You can use this website for python 3

repl.it

Here is your code: https://repl.it/repls/DarkvioletRealLocatorprogram#main.py

Daniel
  • 63
  • 5
0

Use raw_input in place of input in python2. Ex:- character_name = raw_input("Select a name for your character: ")