Steve is building a board game in which players trade colored gems for cards. Implement the following three functions:
def can_afford(price, gems):
pass
def purchase_card(price, gems):
pass
def compute_discount(card_count):
pass
1. can_afford
True when the available gems are sufficient; otherwise, produce False.2. purchase_card
3. compute_discount
Also explain why the selected data structures are suitable.
price = [1, 1, 1, 0, 2]
gems = [2, 1, 0, 3, 0]
card count = [3, 0, 1, 1, 2]
can_afford: True
updated gems: [1, 0, 0, 3, 0]
discounts: [1, 0, 0, 0, 1]
The affordability result is True because the supplied gems cover the listed price, and the updated counts show the required gems removed. The discount list is the result expected from the supplied card counts.
The following example is also part of the prompt:
Input: 0
1
print('OK')
Output: