我有这样的代码:
n = list(input().split()) #Input score in alphabet
for i in n :
if i == "E" :
print("You Have Bad Score") #if you have an E score, then you cant pass
elif len(n) < 7 :
print("Your score does not qualify") #must enter at least 8 values
else :
print("You pass")
# Output
A B C C D D D E = Your have bad score
A B B A A B B C = You Pass
A B B B A = Your score doesn't qualify
但是我的代码中的问题是,当我输入ABCCDDDE时,输出为“ You Pass”而不是“ You score bad”。你能帮助我吗 ?
您的代码有一些错误的类型或错误:1.x
应该为n
。其次,尝试使用更具描述性的变量名来帮助您。[注意-您仍然必须修复/解决多个打印语句问题...]
试试这个应该可以帮助您找到答案。
scores = list(input().split()) #Input score in alphabet
print(scores) # you can comment this out
for s in scores:
if any(s == 'E' for s in scores):
print("You Have Bad Score") # earlier bail-out when `E` scores.
break
elif len(scores) < 7 :
print("Your score does not qualify") #must enter at least 8 values
else :
print("You pass")
# Output
# A B C C D D D E = Your have bad score
# A B B A A B B C = You Pass
#A B B B A = Your score doesn't qualify
# Sample Run - with # first list of given scores:
A B C C D D D E
['A', 'B', 'C', 'C', 'D', 'D', 'D', 'E']
You Have Bad Score # changed as the new Req. asked!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句