Python如何读取代码?

2024-04-20 04:02:38 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码

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!")

当它问问题的时候,对于“y”,它直接进入“woo-hoo!”。我想它做的是打印“它的作品”,但如果你键入n它只是去胡呼。请帮忙


Tags: andtotestimportyou密码getif
2条回答

我建议使用distutil的^{}来覆盖所有情况

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!")

这应该起作用:

ans1 = input('Do you Take the english test? [Y/N]').strip()

if ans1.lower() == 'y':
    print("It works")
else:
    print("Woo Hoo!")

相关问题 更多 >