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!")
  • 相关阅读:
    交互题
    线段树
    最小生成树
    拓扑排序
    欧拉回路
    RMQ问题
    dfs序与求子树子节点(染了色)的个数
    dp题
    树状数组与离散化
    没做完的题
  • 原文地址:https://www.cnblogs.com/szchenh2010/p/7638035.html
Copyright © 2011-2022 走看看