zoukankan      html  css  js  c++  java
  • while/for循环+if猜年龄

    初学python,贴一段代码!
    1. 先来个猜年龄的玩法

     1 _oldboy_age = 56
     2 count = 0
     3 while count <3:
     4     guess_age = int(input("guess_age:"))
     5     if guess_age == _oldboy_age:
     6        print("yes ,you right!")
     7        break
     8     elif guess_age > _oldboy_age:
     9           print("think smaller")
    10     else:
    11            print("think bigger")
    12 
    13     count +=1
    14     if count == 3:
    15         confirm = input("Do want to keep guessing?")
    16         if confirm != 'n':
    17             count = 0
    18 
    19 
    20 else:
    21 
    22     print("you have try too much times,get off!")
     1 _oldboy_age = 56
     2 
     3 for a in range(3):
     4     guess_age = int(input("guess_age:"))
     5     if guess_age == _oldboy_age:
     6        print("yes ,you right!")
     7        break
     8     elif guess_age > _oldboy_age:
     9           print("think smaller")
    10     else:
    11         print("think bigger")
    12 
    13 else:
    14 
    15     print("you have try too much times,get off!")
  • 相关阅读:
    适配器
    装饰器
    getOwnPropertyDescriptor
    发布订阅
    策略模式
    window.requestAnimationFrame() 和 window.cancelAnimationFrame()
    L1-056 猜数字
    L1-055 谁是赢家
    L1-054 福到了
    L1-053 电子汪
  • 原文地址:https://www.cnblogs.com/szchenh2010/p/7638035.html
Copyright © 2011-2022 走看看