zoukankan      html  css  js  c++  java
  • 流程控制练习

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

     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:
  • 相关阅读:
    三个问题
    2014-7
    2014-5
    2014-2
    2014-1
    2013-11
    mysql中对表操作----为所有列插入数据
    Redis做消息队列
    收集Nginx-access,Nginx-error日志
    .Nginx安装filebeat收集日志:
  • 原文地址:https://www.cnblogs.com/Andy963/p/5312272.html
Copyright © 2011-2022 走看看