Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Program does not end
#1
Hello,

I'm working on a homework assignment and I'm having issues with the program not ending after an option other than "1" is selected. When I select option 2, the program prints "High card is coming soon" but continues to prompt for an amount instead of ending. It happens on options 3 as well as the invalid options. I'm also having an issue where if the cost is more than the payment, it gives the appropriate response "You did not pay enough." but then gives a traceback error and tries to continue instead of terminating.

Here's the assignment:

Then your program will make a decision to do something based on the option:

If the user chooses option 1, your program will play the Make Change game
If the user chooses option 2, High Card, your program will display the message “High Card is coming soon.”
If the user chooses option 3, your program will do nothing - your program should just end naturally.
If the user chooses an invalid option (option < 1 or option > 3) your program should display the message “Invalid option” and terminate naturally. Do not try to re-prompt for input.

The Make Change game does the following:
Allow a clerk to enter the amount of money a customer owes for a purchase and the amount of money the customer paid.
If the user did not pay enough, just display a message telling them they did not pay enough - do not try to ask for any more money.
If they paid enough, the game should calculate and display the amount of change, then break it down into the number of dollars, quarters, dimes, nickels and pennies to return to the customer.


Here's my code:

# Display game menu
print("Menu")
print("1. Make Change")
print("2. High Card")
print("3. Quit")
print( )

# Enter option
option=int(input("Enter a number to choose an \
option: "))

# Decision display
if option == 1:
    print( )
    print('Make Change Game')
elif option == 2:
    print( )
    print('High Card is coming soon.')
elif option == 3:
    print ()
elif option < 1 or option > 3:
    print( )
    print('Invalid option')

# Define payment and cost
payment = float(input("Enter the payment amount: "))
cost = float(input("Enter the cost: "))

if payment < cost:
    print('You did not pay enough.')
else:
    change = payment - cost

# Display the change due
print('\nchange due: $',format(change, '.2f'))

# Calulate number of dollars
dollars = int(change//1)
print('Dollars:',dollars)

# Convert change
change = int(((change-dollars) + .005)* 100)

# Calculate number of quarters
quarters = change // 25
print('Quarters:',quarters)
change = change - (quarters * 25)

# Calculate number of dimes
dimes = change // 10
print('Dimes:',dimes)
change = change - (dimes * 10)

# Calculate number of nickels
nickels = change // 5
print('Nickels:',nickels)
change = change - (nickels * 5)

# Pennies due
pennies = change
print('Pennies:',pennies)
Any help is appreciated.
Thank you!
Reply


Messages In This Thread
Program does not end - by Cheezygrapes - Jun-18-2018, 12:02 AM
RE: Program does not end - by ichabod801 - Jun-18-2018, 12:08 AM
RE: Program does not end - by cryomick - Jun-18-2018, 08:11 AM
RE: Program does not end - by Cheezygrapes - Jun-19-2018, 02:40 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020