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()
If this is Python 2, you need to use raw_input
instead of input
. (Or switch to Python 3)
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
Use raw_input in place of input in python2 . Ex:- character_name = raw_input("Select a name for your character: ")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.