为了账号安全,请及时绑定邮箱和手机立即绑定

python小练习:带循环和条件判断的用户输入?

python小练习:带循环和条件判断的用户输入?

Go
宝慕林4294392 2019-02-11 14:10:52
python小练习:带循环和条件判断的用户输入。使用raw_input()函数来提示用户输入一个1和109之间的数,如果用户输入的数满足这个条件,显示成功并退出。否则显示一个错误信息然后再次提示用户输入数值,直到满足条件为止。 谢谢
查看完整描述

2 回答

?
萧十郎

TA贡献1815条经验 获得超11个赞

123456num = int(raw_input("Please input your number:"))while not 0<num<100:    print "Please input a num between 1 and 100!"    num = int(raw_input("Please input your number:"))else:    print num


查看完整回答
反对 回复 2019-03-14
?
长风秋雁

TA贡献1757条经验 获得超7个赞

Num_Random = random.randint(1, 109)
print('The randomly generated value is :', Num_Random)
num = int(input('please enter a number betmeen 1 and 109:'))
while 1 < num < 110:
if num == Num_Random:
print('Congratulations,you got it!')
break
else:
print('Answer is wrong,please re-enter the number between 1~109!')
num = int(input('please enter a number betmeen 1 and 109:'))



查看完整回答
反对 回复 2019-03-14
  • 2 回答
  • 0 关注
  • 1015 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信