4.9k views
3 votes
Write a function number_of_pennies() that returns the total number of pennies given a number of dollars and (optionally) a number of pennies. Ex: If you have $5.06 then the input is 5 6, and if you have $4.00 then the input is 4. Sample output with inputs: 5 6 4 506 400

User Rufel
by
5.1k points

1 Answer

3 votes

Answer:

The function is as follows:

def number_of_pennies(dollars,pennies=0):

return dollars*100+pennies

Step-by-step explanation:

This defines the function

def number_of_pennies(dollars,pennies=0):

This returns the number of pennies

return dollars*100+pennies

Note that, if the number of pennies is not passed to the function, the function takes it as 0

User Michael Boyer
by
5.2k points