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:'))
相似回答