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

python小练习:带循环和条件判断的用户输入。使用raw_input()函数来提示用户输入一个1和109之间的数,如果用户输入的数满足这个条件,显示成功并退出。否则显示一个错误信息然后再次提示用户输入数值,直到满足条件为止。 谢谢

宝慕林4294392
浏览 1064回答 2
2回答

萧十郎

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

长风秋雁

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!')breakelse:print('Answer is wrong,please re-enter the number between 1~109!')num = int(input('please enter a number betmeen 1 and 109:'))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go