You have x no. of 5 rupee coins and y no. of 1 rupee coins. You want to purchase an item for amount z. The shopkeeper wants you to provide exact change. You want to pay using minimum number of coins. How many 5 rupee coins and 1 rupee coins will you use? If exact change is not possible then display -1.
‼️‼️write an algorithm for this question‼️‼️
Answers
Answer:
z = int(input("Enter price of item"))
a = int(input("Enter coins of rs 5 available"))
b = int(input("Enter coins of rs 1 available"))
x = z//5
y = z%5
if (x>a or y>b):
print(-1)
else:
print("5 rupee coins needed are ",x)
print("1 rupee coins needed are ",y)
def chiller_jaadu(price, fives, ones):
remaining_fives, remaining_ones = fives, ones
fives_required, ones_required = price // 5, price % 5
if fives_required > remaining_fives:
ones_required += 5 * (fives_required - remaining_fives)
remaining_fives = 0
else:
remaining_fives -= fives_required
if ones_required > remaining_ones:
return -1
else:
remaining_ones -= ones_required
return f"Fives: {fives - remaining_fives}\nOnes: {ones - remaining_ones}"
fives, ones = int(input("five coins: ")), int(input("one coins: "))
print(chiller_jaadu((price := float(input("price: "))), fives, ones))