Ich habe ein etwas langwieriges und repetitives Programm, in das ich andere Module importiere, um dann alle gesammelten Informationen in einen vervollständigten Satz zusammenzufassen. Das Problem, das ich habe, ist alles, was ich definiert hatte, bevor ich zum nächsten Teil übergehe, der sich als NameError zeigt.NameError nach dem Versuch, importierte Module anzuwenden
Hier ist der Code:
import number
print("Hello! \nWhat is your name?")
myName = input()
print("Well, " + myName + ", I think it is time for us to play a
little game.")
print("First, I need to know how old you are. Please
type your age using only numbers.")
while True:
age = input()
try:
if age:
age = float(age)
print("Great!\nNow, where do you live " + myName + "?")
import Place
except ValueError:
print("I'm sorry, I did not understand your answer. Please only use digits and no decimals.")
Hier ist der Platz Modul:
print("As a reminder, I am unable to tell the difference between
places and anything else you respond with. You can make me sound
silly, or you can just answer the question so everything makes sense
in the end!")
place = input()
print("Alright!\nNow what is your
gender?")
print("While today's society has more than two ways to
describe gender, please only use male or female for the sake of
simplicity!")
while True:
gender = input()
if gender == "male":
print("Your name is " + myName + " and you are " + age + " years old. You are a " + gender + " and you live in " + place + "!")
import Answer
if gender == "MALE":
print("Your name is " + myName + " and you are " + age + " years old. You are a " + gender + " and you live in " + place + "!")
import Answer
if gender == "Male":
print("Your name is " + myName + " and you are " + age + " years old. You are a " + gender + " and you live in " + place + "!")
import Answer
if gender == "FEMALE":
print("Your name is " + myName + " and you are " + age + " years old. You are a " + gender + " and you live in " + place + "!")
import Answer
if gender == "Female":
print("Your name is " + myName + " and you are " + age + " years old. You are a " + gender + " and you live in " + place + "!")
import Answer
if gender == "female":
print("Your name is " + myName + " and you are " + age + " years old. You are a " + gender + " and you live in " + place + "!")
import Answer
else:
print("Are you a male or female?")
Hier ist die Antwort-Modul:
while True:
print("Did I get everything correct?\nPlease say yes or no.")
answer = input()
if answer == "Yes":
print("Great! Thanks for playing!")
break
if answer == "yes":
print("Great! Thanks for playing!")
break
if answer == "YES":
print("Great! Thanks for playing!")
break
elif answer == "no":
print("Okay! To make sure I avoid any errors, we must start from the beginning!")
import Self_Story
elif answer == "No":
print("Okay! To make sure I avoid any errors, we must start from the beginning!")
import Self_Story
elif answer == "NO":
print("Okay! To make sure I avoid any errors, we must start from the beginning!")
import Self_Story
else:
print("I'm sorry, I did not understand that.")
Hier ist die Fehlermeldung:
Traceback (most recent call last):
File "/Users/Maddiefayee/Documents/Self_Story.py", line 12, in <module>
import Place
File "/Users/Maddiefayee/Documents/Place.py", line 20, in <module>
print("Your name is " + myName + " and you are " + age + " years old. You are a " + gender + " and you live in " + place + "!")
NameError: name 'myName' is not defined
Da dies veröffentlicht wurde glaube ich, ich habe die Formatierung für die Buchung des Codes, Entschuldigung, noch wirklich neu in diesem! –
Bitte korrigieren Sie Ihre Formatierung. Klicken Sie auf Bearbeiten, fügen Sie Ihren Code ein und drücken Sie Strg + K (oder Cmd + K). Wenn du gerade dabei bist, poste bitte eine MVCE. – SuperSaiyan
In welcher Zeile bekommen Sie genau den Fehler? Könnten Sie die Fehlermeldung auch einfügen? – KartikKannapur