16-老虎机2
原题链接:35067.小派专属2024-12-12 17:25:10
发布于:江苏
import turtle,random
#step1:窗口设置
sc = turtle.Screen()
sc.bgpic('machine.png')
sc.setup(450,550)
#step2:设置图标
icon = ['apple.gif','cherry.gif','grape.gif','heart.gif','orange.gif','seven.gif']
i=0
#利用循环注册图标
while True:
turtle.register_shape(icon[i])
i += 1
if i>5:
break
sc.tracer(False)#屏幕不显示过程
#step3:创建画笔(抬起画笔,移动位置,设置形状)
a = turtle.Turtle()
b = turtle.Turtle()
c = turtle.Turtle()
a.penup()
b.penup()
c.penup()
a.goto(-118,70)
b.goto(-23,70)
c.goto(73,70)
a.shape('apple.gif')
b.shape('apple.gif')
c.shape('apple.gif')
#step5:显示金额
pen = turtle.Turtle()
pen.penup()
pen.goto(-30,-180)
pen.hideturtle()
pen.pencolor('goldenrod1')
pen.write('100',font = ('Rockwell',40))
sc.update()#搭配sc.tracer(0)显示所有图标
money = 100
while money > 0:
# 输入弹窗
#numinput(标题,提示,默认值,最小值,最大值)
n = turtle.numinput('投币', '请输入投币金额', 10, 1, money)
money -= n
pen.clear()
pen.write(int(money), font = ('Consolas', 40))
s1 = random.choice(icon)
s2 = random.choice(icon)
s3 = random.choice(icon)
a.shape(s1)
b.shape(s2)
c.shape(s3)
## if (s1 == s2 == s3):
if s1==s2 or s1 ==s3 or s2==s3:
money += 10*n
sc.update()
#print(s1)
# 滚动抽奖
turtle.done()
homework
f = {'香蕉':5.5, '樱桃':15, '橙子':6, '梨子':2.3}
f['樱桃'] += 3
f.pop('香蕉')
print(f)
这里空空如也
有帮助,赞一个