python水果店实训题

img

img


如图,该提问只用完成1235,即使给出了参考代码但是对于我来说还是不行啊,直接复制粘贴是运行不了的,求各位完成题目补充代码

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 你可以看下这个问题的回答https://ask.csdn.net/questions/7677448
  • 这篇博客你也可以参考下:python教你两行代码添加水印,超级简单~
  • 除此之外, 这篇博客: 用【Python】写了一个水果忍者小游戏,玩过之后爱不释手中的 六、游戏开始与结束的画面 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:
    1.def show_gameover_screen():
    
    
    2.    gameDisplay.blit(background, (0,0))
    
    
    3.    draw_text(gameDisplay, "FRUIT NINJA!", 90, WIDTH / 2, HEIGHT / 4)
    
    
    4.    if not game_over :
    
    
    5.        draw_text(gameDisplay,"Score : " + str(score), 50, WIDTH / 2, HEIGHT /2)
    
    
    6. 
    
    
    7.    draw_text(gameDisplay, "Press a key to begin!", 64, WIDTH / 2, HEIGHT * 3 / 4)
    
    
    8.    pygame.display.flip()
    
    
    9.    waiting = True
    
    
    10.    while waiting:
    
    
    11.        clock.tick(FPS)
    
    
    12.        for event in pygame.event.get():
    
    
    13.            if event.type == pygame.QUIT:
    
    
    14.                pygame.quit()
    
    
    15.            if event.type == pygame.KEYUP:
    
    
    16.                waiting = False
    

    •show_gameover_screen()函数显示初始游戏画面和游戏结束画面。

    •pygame.display.flip()将只更新屏幕的一部分,但如果没有参数传递,则会更新整个屏幕。

    •pygame.event.get()将返回存储在pygame事件队列中的所有事件。

    •如果事件类型等于quit,那么pygame将退出。

    •event.KEYUP事件,当按键被按下和释放时发生的事件。

    在这里插入图片描述

  • 您还可以看一下 董付国老师的Python可以这样学(第12季:音频处理与视频处理实战)课程中的 补充:删除视频画面中的水印小节, 巩固相关知识点

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^

# -*- coding: utf-8 -*-

# 创建两个列表
fruits = [
    {'name': '猕猴桃', 'quantity': 125},
    {'name': '苹果', 'quantity': 315},
    {'name': '香蕉', 'quantity': 80},
    {'name': '草莓', 'quantity': 50},
    {'name': '葡萄', 'quantity': 70},
    {'name': '砂糖橘', 'quantity': 200}
]
prices = [
    {'name': '猕猴桃', 'price': 15},
    {'name': '苹果', 'price': 8},
    {'name': '香蕉', 'price': 5},
    {'name': '草莓', 'price': 30},
    {'name': '葡萄', 'price': 12},
    {'name': '砂糖橘', 'price': 6}
]


# 合并两个列表
length = len(fruits)
merged_fruits = []  # 存储当前的库存信息
for idx, fruit in enumerate(fruits):
    merged_fruits.append({**fruit, **prices[idx]})

print("#################################")
print(f"合并后的列表如下:\n{merged_fruits}")
print("#################################")

# 输出quantity < 100的水果列表
small_inv_fruits = []
for fruit in merged_fruits:
    if fruit["quantity"] < 100:
        small_inv_fruits.append(fruit)

print("#################################")
print(f"库存小于100的水果列表如下:\n{small_inv_fruits}")
print("#################################")

sorted_fruits = sorted(merged_fruits, key=lambda f: f.get("quantity"))
sorted_fruits.reverse()  #  降序排列

# 根据水果数量降序输出水果的名称,数量和单价
print("#################################")
print("根据水果数量降序输出水果的名称,数量和单价:")
for fruit in sorted_fruits:
    print(f"名称:{fruit.get('name')}   数量:{fruit.get('quantity')}   单价:{fruit.get('price')}")
print("#################################")

purchase_fruits = {
    '猕猴桃': 5,
    '草莓': 2,
    '砂糖橘': 5
}

print("#################################")
print("更新库存:")
for fruit in merged_fruits:
    amount = purchase_fruits.get(fruit['name'], 0)
    fruit['quantity'] -= amount
print(f"最新库存为: {[f['name'] + ':' + str(f['quantity']) for f in merged_fruits]}")

print("计算金额:")
total = 0
for fruit in merged_fruits:
    name, price = fruit['name'], fruit['price']
    amount = purchase_fruits.get(name, 0)
    if amount > 0:
        price = price * 0.9 if price > 10 else price
        total += amount * price

print(f"金额为:{total}")
print("#################################")