Thank you for posting an effort. Good start. Some people merely post homework questions.
Using python is a good learning tool. Did you test your program or merely write it as conjecture? If I were to run your program it would fail on the first line
NameError: name 'price' is not defined
Next, indentation is an essential part of python syntax. Post python code here using code tags. Put your code into the edit window, highlight it with your mouse, and click the # icon found above the edit window. And if you have some other hardware configuration, enter
[c o d e] at the start of your program, and
[ / c o d e ] at the program end.
Remove the spaces between the square brackets.
Great, now that you've decided to actually try python, and to try harder to post python so that we don't have to guess the nesting of your if statements we'll get on with the show.
According to python documents, the compound statements are if while for try with def class
Code:
compound_stmt ::= if_stmt
| while_stmt
| for_stmt
| try_stmt
| with_stmt
| funcdef
| classdef
The code you show contains if. Therefor, contrary to your claim, you used compound statements.
Code:
'''
Make change using quarters, dimes, and nickels.
No division!
Limits: the amount of change is less than a buck and a multiple of 5 cents.
invoke the doctests as the shell command
$ python -m doctest -v module_name.py
'''
def change(amount,value):
'''
return a 2-tuple of the resulting amount and
the number of coins used of value value.
doctests:
>>> change(45,25)
(20, 1)
>>> change(20,10)
(0, 2)
'''
i = 0
while value <= amount:
amount -= value
i += 1
return (amount, i, )
A solution without compound statements:
index into a dictionary of precomputed change for keys list(range(100))[0:100:5] .