新的猜数字游戏
jici=1
while jici:
import random,easygui
secret = random.randint(1,99)
easygui.msgbox("已藏好了一个数,猜猜看!!,给你6次机会")
tries = 6
while tries:
guess = easygui.integerbox("请输入一个1--100的数:")
tries -= 1
if guess == secret:
jihui = easygui.buttonbox("太棒了!我藏好的数正是%d" % secret,choices=['继续','不玩了'])
tries = 0
elif guess > secret and tries != 0:
easygui.msgbox("猜大了,你还有%d次机会" % tries)
elif guess < secret and tries != 0:
easygui.msgbox("猜小了,你还有%d次机会" % tries)
else:
jihui = easygui.buttonbox("太笨了,我藏好的数是%d 啦" % secret,choices=['继续','不玩了'])
#这里的tries =0 或者说已经猜出来了,tries也赋值为0,这时就要问要不要继续游戏,根据用户的选择给出相应的答案
if jihui == '继续':
jici = 1
else:
jici = 0
easygui.msgbox("游戏结束")
jici =1
while jici:
import random, easygui
secret = random.randint(1,99)
easygui.msgbox("我已经藏好了一个数,猜猜看,给你6次机会!")
for tries in range(6):
guess = easygui.integerbox("请输入一个1--100的数:")
if guess == secret:
jihui = easygui.buttonbox("太棒了!我藏好的数正是%d" % secret,choices=['继续','不玩了'])
break
elif guess > secret and tries != 5:
easygui.msgbox("猜大了,你还有%d次机会" % (5-tries))
elif guess < secret and tries != 5:
easygui.msgbox("猜小了,你还有%d次机会" % (5-tries))
else:
jihui = easygui.buttonbox("太笨了,我藏好的数是%d 啦" % secret,choices=['继续','不玩了'])
#这里的tries =5 或者说已经猜出来了,这时就要问要不要继续游戏,根据用户的选择给出相应的答案
if jihui == '继续':
jici = 1
else:
jici = 0
easygui.msgbox("游戏结束")