我输错了什么? 我收到以下错误:
[RUN OUTPUT]
Please pick the number next
to your mood:
1) Happy
2) Indifferent
3) Sad
1,2, or 3?
2
:-|
would you like to choose again? y\n :
y
Traceback (most recent call last):
File ".\scratch.py", line 35, in <module>
main()
File ".\scratch.py", line 5, in main
again()
File ".\scratch.py", line 8, in again
yn = input('would you like to choose again? y\\n :\n')
File "<string>", line 1, in <module>
NameError: name 'y' is not defined
[/ RUN OUTPUT]
[CODE]
#!/usr/bin/python
def main():
select()
again()
def again():
yn = input ('would you like to choose again? y\\n :\n')
if yn == 'y':
select()
elif yn == 'n':
print('bye')
quit()
else:
print('your selection doesn''t make sense, good by')
quit()
def select():
print(""" Please pick the number next
to your mood:
1) Happy
2) Indifferent
3) Sad""")
choice = input ('1,2, or 3?\n')
if choice == 1:
print(':-)')
elif choice == 2:
print(':-|')
elif choice == 3:
print(':-(')
else:
print("you must be drunk")
if __name__=='__main__':
main()
[/代码]
答案 0 :(得分:0)
尝试使用
raw_input('would you like to choose again? y\\n :\n')
而不是
input ('would you like to choose again? y\\n :\n')