• Guess_name


    猜数字游戏,程序自动生成一个0-100的随机数,用户可以猜测3次,3次后可选择是否继续猜测。

    #!/usr/bin/env python
    #-*- coding:utf-8 -*-
    # Li Rong Yang
    """
    This game lets user guess he/her age.
    """
    
    import random
    oldman_age = random.randint(0,100)#生成一个随机数
    count = 0
    
    while True:
        if count == 3:
            break
    
        user_guess = int(input("Please guess age. "))#提示用户输入一个猜测的数字
    
        if user_guess > oldman_age:                   #判断猜测数字和生成数字是否一致
            print("large...")
        elif user_guess < oldman_age:
            print("smaller...")
        else:
            print("He/Her age is {_age}.Yes you got it. very nice".format(__age = user_guess))
            break
    
        count += 1 #计数+1
        if count == 3: #判断用户猜测乐几次,猜测3次后提示用户是否继续
            inquiry = input("Do want to continue? Y/N")
            if inquiry != "N" and inquiry != "n":
                count = 0
    
    if user_guess != oldman_age:
        print("Welcome to use login this game.")
    

      

  • 相关阅读:
    bzoj 4007
    bzoj 2190
    bzoj 2186
    bzoj 2005
    bzoj 2721
    bzoj 1951
    CF919F
    CF1005F
    CF1019C
    bitset用法详解
  • 原文地址:https://www.cnblogs.com/lirongyang/p/10485639.html
Copyright © 2020-2023  润新知