python猜数游戏

#!/usr/bin/env python
# coding:utf-8
# __author__ = 'cheng'
# Date: 8/14/18


import random
j = 5
while True:
    n = random.randint(1, 50)
    # print(n)
    for i in range(j):
        num = input("please input num: ")
        if num.isdigit():
            num = int(num)
            # print(num)
            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()

 

你可能感兴趣的:(python猜数游戏)