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