程序功能:
1,用户输入数字,当用户输入指定数字时候,输出他输入的循环那次
2,第二次询问是否还要输
3,如果no 则 终止
4,如果yes则继续输入
判断输入是否大于首次输入的
如果大于则开始循环输出他第二次的lucky num
否则循环让输入,直到它输入为大于首次
#!/usr/bin/env python ####coding:utf8 lucky_num=input(‘lucky_num:‘) count=1 while count < 100000: # count+=1 print ‘loop:‘,count if lucky_num==count: print ‘you have got your lucky num:‘,count op=raw_input("if you want to continue(y/n):") if op=="n":break else: while 1: lucky_num_new=input(‘lucky_num:‘) if lucky_num>lucky_num_new: print "too small,you should bigger than %s pls reinput your lucky num:"% lucky_num else: lucky_num=lucky_num_new break # print ‘loop:‘,count count+=1 else: print ‘wow. that fantastic‘,count
执行结果:
[email protected]:~/t$ python t.py lucky_num:5 loop: 1 loop: 2 loop: 3 loop: 4 loop: 5 you have got your lucky num: 5 if you want to continue(y/n):y lucky_num:3 too small,you should bigger than 5 pls reinput your lucky num: lucky_num:2 too small,you should bigger than 5 pls reinput your lucky num: lucky_num:4 too small,you should bigger than 5 pls reinput your lucky num: lucky_num:9 loop: 6 loop: 7 loop: 8 loop: 9 you have got your lucky num: 9 if you want to continue(y/n):
时间: 2024-10-23 22:09:43