zoukankan      html  css  js  c++  java
  • for循环语句示例应用

     1 age = 22
     2 #优化前
     3 '''
     4 for i in  range(10):
     5     guess_num = int(input('input your guess num:'))
     6     if guess_num == age :
     7         print('Congratulations ! you got it.')
     8     elif guess_num > age:
     9         print('Think smaller!')
    10     else:
    11         print('Think Big...')
    12 '''
    13 #优化后:要求输入用户名输入正确以后不执行语句
    14 '''
    15 for i in  range(10):
    16     if i < 3:
    17         guess_num = int(input('input your guess num:'))
    18         if guess_num == age :
    19             print('Congratulations ! you got it.')
    20             break #跳出整个循环
    21         elif guess_num > age:
    22             print('Think smaller!')
    23         else:
    24             print('Think Big...')
    25     else:
    26         print('too many attumt.bye')
    27         break
    28 '''
    29 #再优化:要求循环3次后询问一次
    30 counter = 0
    31 for i in  range(10):
    32     print('counter',counter)
    33     if counter < 3:
    34         guess_num = int(input('input your guess num:'))
    35         if guess_num == age :
    36             print('Congratulations ! you got it.')
    37             break #跳出整个循环
    38         elif guess_num > age:
    39             print('Think smaller!')
    40         else:
    41             print('Think Big...')
    42     else:
    43         continue_confirm = input('Do you want to continue because you are stupid:')
    44         if continue_confirm == 'y':
    45             counter = 0
    46             continue #跳出本次循环
    47         else:
    48             print('bye')
    49             break
    50     counter += 1    #counter = counter + 1
  • 相关阅读:
    TF-IDF
    3.路径模板两张表设计
    6.订单支付回调接口
    5.创建订单并生成支付链接接口
    5.使用ES代替whoosh全文检索
    4.docker基本使用
    3.ubuntu安装docker
    2.课程全文检索接口
    1.搜索引擎工作原理
    7.视频播放页面接口开发
  • 原文地址:https://www.cnblogs.com/liangml/p/5953612.html
Copyright © 2011-2022 走看看