age = float(raw_input("Enter your age: "))
grade = int(raw_input("Enter your grade: "))
if age >= 8:
if grade >= 3:
print "You can play this game."
else:
print "Sorry, you can't play the game."
如果年龄为真且等级为假,则此程序打印错误的输出。但如果年龄为假,则打印正确的输出。
为什么会这样?
答案 0 :(得分:1)
您将保留age >= 8
但grade < 3
无法控制流量的可能性。您可以使用and
语句
age = float(raw_input("Enter your age: "))
grade = int(raw_input("Enter your grade: "))
if age >= 8 and grade >= 3:
print "You can play this game."
else:
print "Sorry, you can't play the game."
答案 1 :(得分:0)
age = float(raw_input("Enter your age: "))
grade = int(raw_input("Enter your grade: "))
if age >= 8:
if grade >= 3:
print"You can play this game."
else:
print"Sorry , you can't play the game."
else:
print "Sorry , you can't play the game."
答案 2 :(得分:0)
您必须在嵌套的if / else语句中包含'else'条件:
age = float(raw_input("Enter your age: "))
grade = int(raw_input("Enter your grade: "))
if age >= 8:
if grade >= 3:
print "You can play this game."
else:
print"Sorry, you can't play this game."
else:
print "Sorry, you can't play this game."