Q1) Write a program that prompts the user to input an integer that represents cents.The program will then calculate the smallest combination of coins that the user has.
For example, 27 cents is 1 quarter and 2 pennies.
Note : given $bills the change should come
has to run from pycharm.
def cents_to_coins(cents): if cents >= 100: return str(cents // 100) + " Dollars " + cents_to_coins(cents - ((cents // 100) * 100)) elif cents >= 50: return str(cents // 50) + " Half dollars " + cents_to_coins(cents - ((cents // 50) * 50)) elif cents >= 25: return str(cents // 25) + " Quarters " + cents_to_coins(cents - ((cents // 25) * 25)) elif cents >= 10: return str(cents // 10) + " Dimes " + cents_to_coins(cents - ((cents // 10) * 10)) elif cents >= 5: return str(cents // 5) + " Nickels " + cents_to_coins(cents - ((cents // 5) * 5)) elif cents > 0: return str(cents) + " Pennies" else: return "" def main(): cents = int(input("Enter cents:")) print(cents, " cents is ", cents_to_coins(cents)) main()
Get Answers For Free
Most questions answered within 1 hours.