(SOLVED) Code in Python pleasee

Discipline: IT, Web

Type of Paper: Question-Answer

Academic Level: Undergrad. (yrs 3-4)

Paper Format: APA

Pages: 1 Words: 275


Code in Python pleasee

TTBank has gift cards, and they come in three different denominations: $10, $30, and $50. Jugg has collected a lot of them!

Jugg would like to use N cards to buy an item, which costs M dollars. However, he doesn't want to leave a remaining balance on any cards he chooses.

How many different ways is Jugg able to buy the item?

Input Format

The first line contains two integers N, M. N is the number of cards, and M is the cost of that item.

Output Format

An integer, representing the number of different ways to buy the item, using the exact number of cards required.

Sample Input


Sample Output



Jugg must use 4 cards to buy an $80 item.

There are 2 ways to do this:

2 $10 gift cards and 2 $30 gift cards. (10+10+30+30=80)

3 $10 gift cards and 1 $50 gift card. (10+10+10+50=80)

 Expert Answer

# Define the denominations of the gift cards
denominations = [10, 30, 50]

# Read the number of cards and the cost of the item from the input
n, m = map(int, input().split())

# Initialize a counter to keep track of the number of ways
# to buy the item using the exact number of cards
counter = 0

# Iterate over all possible combinations of cards
for a in range(n+1):
for b in range(n+1):
for c in range(n+1):
# Check if the number of cards of each denomination is valid
if a + b + c == n:
# Check if the total cost of the item can be paid using the cards
if a*denominations[0] + b*denominations[1] + c*denominations[2] == m:
# If both conditions are satisfied, increment the counter
counter += 1

# Print the result

Here I Have attach the Output for the code :