python小练习:带循环和条件判断的用户输入。使用raw_input()函数来提示用户输入一个1

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

num = 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

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-04-17
第2个回答  2018-04-13
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:'))

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网