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
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 "", line 1, in
NameError: name 'y' is not defined
[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()
Что я пишу неправильно? Я получаю следующую ошибку:
[RUN OUTPUT]
[code] 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 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 "", line 1, in NameError: name 'y' is not defined [/code]
[/RUN OUTPUT]
[CODE]
[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")