首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python -如何让它读取代码?

Python -如何让它读取代码?
EN

Stack Overflow用户
提问于 2016-03-12 19:45:23
回答 2查看 53关注 0票数 0

以下是我的代码

代码语言:javascript
复制
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,它就会发出”呼呼“的声音。请帮帮忙

EN

回答 2

Stack Overflow用户

发布于 2016-03-12 19:49:55

这应该是可行的:

代码语言:javascript
复制
ans1 = input('Do you Take the english test? [Y/N]').strip()

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

Stack Overflow用户

发布于 2016-03-12 20:58:59

我建议使用distutil的strtobool,以便涵盖所有情况

代码语言:javascript
复制
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!")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35957225

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档