安迪_963

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

要求,从用户处得到一个数,打印直到该数,并让用户选择是否继续。如果此数已经输出,则提示过了,并要求再次输入。

 1 # coding: utf-8
 2 p_flag = True
 3 count = 0
 4 
 5 while p_flag:
 6     usr_num = int(input('请输入你要找的数字:'))
 7 
 8     while count < usr_num:
 9         print(count)
10         count += 1
11         if count == usr_num:
12             print('已经得到: %d' % count)
13             choice = input('还要再试一次吗?')
14             if choice == 'y':
15                 break
16             else:
17                 p_flag = False
18                 break
19     else:
20         print('过了!')
21         continue
方案1

 

 1 # coding : utf-8
 2 count = 0
 3 
 4 while count < 1000:
 5     usr_num =  int(input('输入一个数:'))
 6     count += 1
 7     print(count)
 8     
 9     if count == usr_num:
10         print('已经得到: %d' % count)
11         choice = input('还要再试一次吗?(y/n)')
12         if not choice == 'y':
13             break
14     elif count > usr_num:
15         print('过了')
16 
17         
方案2:

 

posted on 2016-03-23 18:17  Andy_963  阅读(295)  评论(0编辑  收藏  举报