Python学习之easygui实现简单小游戏

import random, easygui
secret = random.randint(1, 99)
guess = 0
tries = 0
easygui.msgbox("""Hi! I'm the Dread Pirate Roberts, and I have a secret!
It is a number from 1 to 99. I'll give you 6 tries...""")
while guess != secret and tries < 6:
guess = easygui.integerbox("what's your guess?")
if not guess: break
if guess < secret:
easygui.msgbox(str(guess) + "is too low!")
elif guess > secret:
easygui.msgbox(str(guess) + "is too high!")
tries += 1
if guess == secret:
easygui.msgbox("Great! You got it! Found my secret, you did!")
else:
easygui.msgbox("No more guesses! The number was" + str(secret))

posted @ 2018-11-09 00:43  猫耳君  阅读(1002)  评论(0编辑  收藏  举报