python询问yes_提示用户输入y、yes、n或n

您的完整代码是:def main():

credits = int(input("Enter the total number of credits completed: "))

udcredits = int(input("Enter the number of upper-division credits completed: "))

localcredits = int(input("Enter the number of local credits completed: "))

mrequirements = input("Have you completed all major requirements? ")

before2010 = int(input("In what year did you matriculate? "))

gerequirements = input("Are your general education requirements done? ")

if before2010 < 2010 and credits >= 120 and udcredits >= 40 and localcredits >= 30 and mrequirements[0].lower() == 'y':

print("eligible")

else:

print("ineligible")

if gerequirements[0].lower() == 'y' and credits >= 120 and udcredits >= 40 and localcredits >= 30 and mrequirements[0].lower() == 'y':

print("eligible")

else:

print("ineligible")

main()

变更第6行,将eval()改为int()这样更安全,更好的实践

第9&14行将.lower()添加到mrequirements[0]和gerequirements[0]中,这样即使用户键入大写的Y,测试仍然可以通过。

第9&14行在"y"中添加了引号,因为它保存为Python中input()函数的字符串。否则,if语句将不会返回true

现在应该可以了。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值