95.0k views
4 votes
g Write a function number_of_pennies() that returns the total number of pennies given a number of dollars and (optionally) a number of pennies.

User Sabeer
by
5.3k points

1 Answer

0 votes

In python 3.8:

def number_of_pennies(dollars, pennies = 0):

return (dollars * 100) + pennies

print(number_of_pennies(1))

def number_of_pennies(dollars, pennies = 0): This defines are function and the pennies = 0 sets the default value of pennies equal to 0.

return (dollars * 100) + pennies. This returns the amount of pennies in any amount of dollars and pennies given by the user.

print(number_of_pennies(1)) This prints the return value of our function which is the number of pennies. We don't have to give a number for the amount of pennies because the default value is 0, but we still have to give a value to the dollars.

I hope this helps!

User AlexDan
by
4.4k points