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: 5 dollars and 6 pennies returns 506.



Answer :

Ok, first of all, it is important to understand that this function would depend on 2 variables; the number of dollars (x) and the number of pennies (y). Every dollar is equivalent to 100 pennies. So, if we are given x dollars, we have 100*x pennies. If we also have y pennies, we still get y pennies. We need to add these two to get the total amount of pennies. Thus, the correct function is:
f(x,y)=100*x+y