What To Buy
Part of the Fundamentals section of Coddy's Python journey — lesson 77 of 77.
Challenge
MediumWrite a program that receives three inputs (given):
- A list of prices
- A list of item names
- A budget per item
The program should print:
- A list of items that you can afford within your budget
- How much budget would you need if you bought all of the affordable items
- How many items you couldn't afford
Check the test cases for the output format
Try it yourself
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
# Write your code below
print("Can buy:", affordable_items)
print("Total budget needed:", total_needed)
print("Can't afford:", cant_afford)
All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 48Loops
For LoopWhile LoopBreakContinueRecap - FactorialThe Range FunctionNested LoopRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators9Functions
Declare a FunctionArgumentsReturnRecap - Sigma FunctionRecap - Validation FunctionDefault Values12Iterating Over Sequences
Iterating Over ElementsThe Enumerate FunctionIterating Over Strings Part 1Iterating Over Strings Part 2