Reputation: 409
I'm trying to get "150 cents" to be displayed in shell after I type in
print(dollar_amount(30, 0, 0, 0, 0))
in the idle window. But instead, I get this error message:
TypeError: unsupported operand type(s) for +: 'int' and 'str'
I'm using Python 3.
Here is the question below:
def dollar_amount(nickels, dimes, quarters, loonies, toonies):
'''(int, int, int, int, int) -> str
Upvotes: 0
Views: 67
Reputation: 142166
Use string formatting:
dollar_amount= (nickels * 5) + (dimes * 10) + (quarters * 25) + (loonies * 100) + (toonies * 200)
return "{} cents".format(dollar_amount)
Upvotes: 2
Reputation: 798726
"cents"
is already a string; change the rest.
str(...) + " cents"
Upvotes: 1