使用Python编的猜数字小游戏

import random

secret = random.randint(1, 30)
guess = 0
tries = 0

print("我叫丁丁,我有一个秘密数字!")
print("数字从1到30,你只有6次机会!")

while int(guess) != secret and tries < 6:
    print("你猜的数字是?")
    guess = input()
    if int(guess) < secret:
        print("数字太小了!再猜!")
    elif int(guess) > secret:
        print("数字太大了!再猜!")
    tries = tries + 1
if int(guess) == secret:
    print("你真厉害!恭喜你猜对啦!")
else:
    print("你猜错6次啦,下次再玩吧!")
    print("我的秘密数字是:", secret)

使用Python编的猜数字小游戏_第1张图片

你可能感兴趣的:(软件编程,Python编程)