[Type C] Working with Functions – Chapter 3 Sumita Arora
Table of Contents
1. Write a function that takes an amount in dollars and the dollar-to-rupee conversion price; it then returns the amount converted to rupees. Create the function in both void and non-void forms.
Short Answer: Two functions will be created, one to convert dollars to rupees with a return value, and another to convert dollars to rupees without a return value.
Python
def convert_to_rupees(amount_in_dollars, conversion_rate):
return amount_in_dollars * conversion_rate
def convert_to_rupees_void(amount_in_dollars, conversion_rate):
print("Amount in Rupees:", amount_in_dollars * conversion_rate)
# Example Usage:
amount = 50
rate = 75
print("Converted Amount (with return):", convert_to_rupees(amount, rate))
convert_to_rupees_void(amount, rate)
Explanation:
- The first function
convert_to_rupees
takes the amount in dollars and the conversion rate and returns the converted amount in rupees. - The second function
convert_to_rupees_void
does the same calculation but prints the result instead of returning it.