python float raw-input_这个python程序bug在哪里?有没有高手指教下 age = float(raw_input (...

回答于 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 :)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值