以下是我的代码
import time
print("------------------------------------------")
print(" Welcome to Senpai Quest")
print('------------------------------------------')
time.sleep(3)
print("")
print('You have English next, there is a test. If you hit yes .you go to
class and you get +1 charisma and Knowledge.')
print("")
print('If you hit no, you will skip class and get +1 Courage and +1 risk.')
ans1=str(input('Do you Take the english test? [Y/N]'))
if ans1== ['y']:
print("It works")
else:
print("Woo Hoo!")当它问这个问题时,它会直接说“呼!”。我希望它能打印出"It works“,但如果你输入n,它就会发出”呼呼“的声音。请帮帮忙
发布于 2016-03-12 19:49:55
这应该是可行的:
ans1 = input('Do you Take the english test? [Y/N]').strip()
if ans1.lower() == 'y':
print("It works")
else:
print("Woo Hoo!")发布于 2016-03-12 20:58:59
我建议使用distutil的strtobool,以便涵盖所有情况
from distutils.util import strtobool
ans1=input('Do you Take the english test? [Y/N] ').strip()
if strtobool(ans1):
print("It works")
else:
print("Woo Hoo!")https://stackoverflow.com/questions/35957225
复制相似问题