买什么
本课属于 Coddy Python 学习旅程的“基础知识”单元。第 77 课,共 77 课。
挑战
中等编写一个程序,接收三个输入(已给出):
- 一个价格列表
- 一个商品名称列表
- 每件商品的预算
程序应输出:
- 你在预算范围内买得起的商品列表
- 如果买下所有买得起的商品,需要多少预算
- 你买不起的商品数量
查看测试用例,了解输出格式
亲手试试
prices = input().split(",")
for i in range(len(prices)):
prices[i] = int(prices[i])
items = input().split(",")
budget_per_item = int(input())
affordable_items = []
cant_afford = 0
total_needed = 0
# 在下方编写你的代码
print("Can buy:", affordable_items)
print("Total budget needed:", total_needed)
print("Can't afford:", cant_afford)
基础知识中的所有课
自己练习: Python 在线编译器