92.7k views
5 votes
Create a change-counting game that gets the user to enter the number of coins required to make exactly one dollar. The program should prompt the user to enter the number of pennies, nickels, dimes, and quarters and immediately verify whether they are positive integer numbers. If the total value of the coins entered is equal to one dollar, the program should congratulate the user for winning the game. Otherwise, the program should display a message indicating whether the amount entered was more than or less than one dollar.

User Eyes
by
6.0k points

1 Answer

2 votes

Answer:

In Python:

pennies= int(input("Pennies: "))

while pennies<0:

pennies= int(input("Pennies: "))

nickels = int(input("Nickels: "))

while nickels < 0:

nickels = int(input("Nickels: "))

dimes = int(input("Dimes: "))

while dimes < 0:

dimes = int(input("Dimes: "))

quarters = int(input("Quarters: "))

while quarters < 0:

quarters = int(input("Quarters: "))

dollars = pennies * 0.01 + nickels * 0.05 + dimes * 0.1 + quarters * 0.25

if dollars == 1:

print("Congratulations")

else:

if dollars > 1:

print("More than $1")

else:

print("Less than $1")

Step-by-step explanation:

Prompts the user for pennies and also validates for positive values

pennies= int(input("Pennies: "))

while pennies<0:

pennies= int(input("Pennies: "))

Prompts the user for nickels and also validates for positive values

nickels = int(input("Nickels: "))

while nickels < 0:

nickels = int(input("Nickels: "))

Prompts the user for dimes and also validates for positive values

dimes = int(input("Dimes: "))

while dimes < 0:

dimes = int(input("Dimes: "))

Prompts the user for quarters and also validates for positive values

quarters = int(input("Quarters: "))

while quarters < 0:

quarters = int(input("Quarters: "))

Calculate the amount in dollars

dollars = pennies * 0.01 + nickels * 0.05 + dimes * 0.1 + quarters * 0.25

Check if amount is $1

if dollars == 1:

If yes, prints congratulations

print("Congratulations")

If otherwise, print greater of less than $1

else:

if dollars > 1:

print("More than $1")

else:

print("Less than $1")

User NHK
by
4.5k points