首页 > 代码库 > [py]简易pick lucky num程序

[py]简易pick lucky num程序

程序功能:

1,用户输入数字,当用户输入指定数字时候,输出他输入的循环那次

2,第二次询问是否还要输

3,如果no 则 终止

4,如果yes则继续输入

  判断输入是否大于首次输入的

    如果大于则开始循环输出他第二次的lucky num

    否则循环让输入,直到它输入为大于首次

#!/usr/bin/env python####coding:utf8lucky_num=input(lucky_num:)count=1while 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+=1else:    print wow. that fantastic,count

 

执行结果:

py@lanny:~/t$ python t.py lucky_num:5loop: 1loop: 2loop: 3loop: 4loop: 5you have got your lucky num: 5if you want to continue(y/n):ylucky_num:3too small,you should bigger than 5 pls reinput your lucky num:lucky_num:2too small,you should bigger than 5 pls reinput your lucky num:lucky_num:4too small,you should bigger than 5 pls reinput your lucky num:lucky_num:9loop: 6loop: 7loop: 8loop: 9you have got your lucky num: 9if you want to continue(y/n):

 

[py]简易pick lucky num程序