python猜数游戏

版权声明:请随意转载 https://blog.csdn.net/cheng1804/article/details/81912677
#!/usr/bin/env python
# coding:utf-8
# __author__ = 'cheng'
# Date: 8/14/18


import random
j = 5
while True:
    for i in range(j):
        num = input("please input num: ")
        if num.isdigit():
            num = int(num)
            # print(num)
            n = random.randint(1, 50)
            # print(n)
            if num > n:
                print("too large")
            if num < n:
                print("too small")
            if num == n:
                print("you are right")
                exit()
            print("you have", j-1-i, "choice")
        else:
            print("not a num")
            print("you have", j-1-i, "choice")
    print("game over.... ")
    q = input("play again?  yes/no ")
    if not (q == "yes" or q == "y"):
        exit()

猜你喜欢

转载自blog.csdn.net/cheng1804/article/details/81912677