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.
2. Write a function to calculate the volume of a box with appropriate default values for its parameters. Your function should have the following input parameters:
3. Write a program to have the following functions:
4. Write a function that receives two numbers and generates a random number from that range. Using this function, the main program should be able to print three numbers randomly.
5. Write a function that receives two string arguments and checks whether they are same-length strings (returns True in this case otherwise false).
6. Write a function named nthRoot() that receives two parameters x and n and returns the nth root of x, i.e., x^(1/n). The default value of n is 2.
7. Write a function that takes a number n and then returns a randomly generated number having exactly n digits (not starting with zero). For example, if n is 2, then the function can randomly return a number 10-99, but 07, 02, etc., are not valid two-digit numbers.
8. Write a function that takes two numbers and returns the number that has the minimum one’s digit. For example, if numbers passed are 491 and 278, then the function will return 491 because it has the minimum one’s digit out of the two given numbers (491’s 1 is < 278’s 8).
9. Write a program that generates a series using a function which takes the first and last values of the series and then generates four terms that are equidistant. For example, if two numbers passed are 1 and 7 then the function returns 1, 3, 5, 7.
8. Write a function that takes two numbers and returns the number that has the minimum one’s digit. For example, if numbers passed are 491 and 278, then the function will return 491 because it has the minimum one’s digit out of the two given numbers (491’s 1 is < 278’s 8).
Short Answer: The function compares the one’s digit of two given numbers and returns the number with the minimum one’s digit.
Python def min_ones_digit ( num1 , num2 ):
return num1 if num1 % 10 < num2 % 10 else num2
# Test
print (min_ones_digit( 491 , 278 )) # 491
Explanation:
The function min_ones_digit
compares the one’s digit of two numbers using the modulo operator %
.
It returns the number with the minimum one’s digit.
The test case demonstrates how the function works with two example numbers.