Program function:
1, the user enters the number, when the user enters the specified number, outputs the loop that he entered.
2, the second question whether or not to lose
3, if no is terminated
4, if yes continue to enter
Determines whether the input is greater than the first input
If it is greater then start looping out his second lucky num
Otherwise the loop allows the input until it is entered as greater than the first
#!/usr/bin/env python## # #coding: UTF8Lucky_num=input ('Lucky_num:') Count=1 whileCount < 100000: #count+=1 Print 'Loop:', Countiflucky_num==Count:Print 'You have got your lucky num:', Count op=raw_input ("If you want to continue (y/n):") ifop=="N": Break Else: while1: Lucky_num_new=input ('Lucky_num:') ifLucky_num>lucky_num_new:Print "too small,you should bigger than%s pls reinput your lucky num:"%Lucky_numElse: Lucky_num=lucky_num_new Break #print ' Loop: ', CountCount+=1Else: Print 'Wow. That fantastic', Count
Execution Result:
[Email protected]:~/t$ python t.py lucky_num:5Loop:1Loop:2Loop:3Loop:4Loop:5You have got your lucky num:5ifYou want toContinue(y/N): ylucky_num:3too small,you should bigger than5pls reinput your lucky num:lucky_num:2too small,you should bigger than5pls reinput your lucky num:lucky_num:4too small,you should bigger than5pls reinput your lucky num:lucky_num:9Loop:6Loop:7Loop:8Loop:9You have got your lucky num:9ifYou want toContinue(y/n):
[PY] Simple pick Lucky Num Program