怎么用python编写好玩的程序
猜数游戏.py
import random, easygui
number = random.randint(1, 99)
guess = 0
tries = 0
easygui.msgbox("I have a secret, can you guess?It's a number from 1 to 99. I'll give you 7 tries.")
while guess != number and tries < 7:
guess = easygui.integerbox("What's your guess?", tries+1)
if guess < number:
easygui.msgbox("Your guess is too low.")
elif guess > number:
easygui.msgbox("Your guess is too high.")
tries = tries + 1
if guess == number:
easygui.msgbox("Ha-ha, you're so clever! You got my secret! ")
else:
easygui.msgbox("No more guesses! Better luck next time!")
easygui.msgbox(secret, "secret")
注:此代码是Python2的,我试过Python3运行不了。另外,需要easygui。