Python 猜数字小游戏,3次机会

import random
from time import sleep
#定义一个随机数
answer=random.randint(1,100)
print("You have only 3 chances!")
sleep(3)
print("READY,GO!!!")

#判断是否猜想正确
for i in range(1,4):
    i = i + 1
    # 定义一个猜想数,在1-100之间
    n = int(input("input an number:"))
    if n==answer:
        print("Bingo! You are right!!!")
        break
    elif n>answer:
        print("number > answer!Play again!\n")
    else :
        print("number < answer!Play again!\n")
print('GAME OVER!!!')

你可能感兴趣的:(Python小练习)