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,测试仍然可以通过。"y"
中添加了引号,因为它保存为Python中input()函数的字符串。否则,if
语句将不会返回true现在应该可以了。在
这行代码不能编译。如果要匹配字符
y
,则必须用引号将其括起来以表示字符串。如果没有引号,Python希望y
是一个变量。在所以表达式变成:
^{pr2}$正如您提到的其他代码的问题:
相关问题 更多 >
编程相关推荐