zoukankan      html  css  js  c++  java
  • 第六天Python学习记录

    优化猜年龄游戏,允许用户最多猜3次,中间猜对了,直接跳出循环

    
    
    age = 26
     
    count = 0
    
    while count < 3:#允许用户最多猜3次
        user_guess = int(input(">>:"))
        
        if user_guess == age:
            print("恭喜你,猜对了")
            break
        elif  user_guess < age:
            print("try bigger")
        else:
            print("try smaller")
         
        count += 1
    
    
    
    
    

    优化猜年龄游戏,允许用户最多猜3次,猜了3次之后,再问是否还想玩,如果用户选有,则再允许猜3次,以此往复

    age = 26
     
    count = 0
    
    while count < 3:#允许用户最多猜3次
        user_guess = int(input(">>:"))
        
        if user_guess == age:
            print("恭喜你,猜对了")
            break
        elif  user_guess < age:
            print("try bigger")
        else:
            print("try smaller")
         
        count += 1
       
         if count == 3: #超过3次,询问用户是否想继续猜
            choice = input("想继续猜吗:y|Y")
            if choice == "y" or choice == "Y":
                count = 0
  • 相关阅读:
    《梦段代码》阅读笔记03
    用户场景
    冲刺!
    冲刺!
    周总结8
    冲刺!
    冲刺!
    PMS权限管理和鉴权过程
    PMS构造函数以及apk如何扫描
    PMS的学习之旅
  • 原文地址:https://www.cnblogs.com/xudachen/p/8315224.html
Copyright © 2011-2022 走看看