回答于 2017/12/10 01:54
age = float(input ("enter your age:"))
grade = int(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.")
----------------------------------------------------
by python 3.x
追问:2017/12/10 08:53
我用的是python 2.7.9,楼上的程序和我的原程序运行结果是一样的。我说的bug意思是当用户输入的数据不同时满足age>=8,grade>=3时,运行结果是程序会反馈"sorry,you can't play this game." 但是,结果是没有此反馈。楼上的程序和我的原程序运行结果是一样的。
回答:2017/12/10 10:20
age = float(input ("enter your age:"))
grade = int(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.")
----------------------------------------------------------
The nested loop not contains the situation when age>=8 but grade <3,
so, you need to add more condition out of the above situation. Hopes helpful :)
回答:2017/12/10 10:53
age = float(input ("enter your age:"))
grade = int(input ("enter your grade:"))
if age >= 8 and grade>=3:
print("you can play this game.")
else:
print("sorry,you can't play this game.")
-----------------------------------------------
If you just want to focus on the condition of (age >=8 and grade >=3),
i think the modified code can be more clear and readable,
and the process is same as the primary outcome you want.
Hopes helpful :)