Найти - Пользователи
Полная версия: Объясните ошибку NameError: name 'a' is not defined
Начало » Python для новичков » Объясните ошибку NameError: name 'a' is not defined
1
TinTeslaMan
Код:
print(“Welcome to Kalimdor.net! Please Enter your name”)
name = input(“Your Name?”)
a == Trall
b == Karn
c == Jaine
d == Artes

if a:print(“Hi,”,Trall)
if b:print(“Hi,”,Karn)
if c:print(“Hi,”,Jaine)
if d:print(“Hi,”,Artes)
else:print(“You can't Enter in Kalimdor.net”)
print(“What you want?”)

name = input(“Freedom for Horde”)
name = input(“Peace on Kalimdor”)
name = input(“Meeting with Oracle”)
name = input(“FROSTMORN!!!”)

if 1:print(“Legion dead,all done”)
if 2:print(“Legion dead,all done”)
if 3:print(“Oracle say's that you need stop war versus Orcs”)
if 4:print(“NOOOOOOOOOOOOOOOOO”)
else:print(“Not avaible”)

Вот что пишет при запуске:
Welcome to Kalimdor.net! Please Enter your name
Your Name? Trall(ввел)
Traceback (most recent call last):
File “C:\Python34\test of WoW.py”, line 3, in <module>
a == Trall
NameError: name ‘a’ is not defined
>>>




Прошу помогите! я осваиваю язык только 3й день! Не бейте!
marvellik
написано- ошибка ! пременная с именем а не найдена. а теперь найди в своем коде где ты задал переменную а? ну и соответственно где заданы b,c,d?
PEHDOM
TinTeslaMan
a == Trall
b == Karn
c == Jaine
d == Artes
оператор == (два знака равно) это сравнение, а не приваивание (связывание)
ошзнакомтесь для начала перед тем как писать код: http://pythonicway.com/python-operators
GaDaub
Traceback (most recent call last):
File “language_survey.py”, line 7, in <module>
my_survey.show_question()
File “C:\Users\DGV\python_work\тестирование\тестирование классов\survey.py”, line 16, in show_question
print(question)
NameError: name ‘question’ is not defined

не находит аргумент( что делать? Код переписан точь в точь из книги
1)программа survey , тут класс, в котором проблема как я понимаю тут def show_question(self): ->print(question) (только какая?)

class AnonymousSurvey():
“”“Сбор анонимных ответов на опросы.”“”
def __init__(self, question):
“”“Сохраняет вопрос и готовится к сохранению ответов.”“”
self.question = question
self.responses =
def show_question(self):
“”“Выводит вопрос.”“”
print(question)
def store_response(self, new_response):
“”“Сохраняет один ответ на опрос.”“”
self.responses.append(new_response)
def my_survey(self):
“”“Выводит все полученные ответы.”“”
print(“Survey results:”)
for response in responses:
print('- ‘ + response)


2)вторая программа
from survey import AnonymousSurvey

# Определение вопроса с созданием экземпляра AnonymousSurvey.
question = “What language did you first learn to speak?”
my_survey = AnonymousSurvey(question)
# Вывод вопроса и сохранение ответов.
my_survey.show_question()
print(“Enter ’q' at any time to quit.\n”)
while True:
response = input(“Language: ”)
if response == ‘q’:
break
my_survey.store_response(responses)
# Вывод результатов опроса.
print(“\nThank you to everyone who participated in the survey!”)
my_survey.show_question()
py.user.next
GaDaub
не находит аргумент( что делать? Код переписан точь в точь из книги
  
print(self.question)

  
question = self.question
print(question)
GaDaub
далала так уже. Тогде ругается на перебор аргументов

File “language_survey.py”, line 7, in <module>
my_survey.show_question()
TypeError: show_question() missing 1 required positional argument: ‘question’
GaDaub
question = self.question

print(question) - - не работает

print(self.question) помогло. Спасибо большое
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB