21. Find the factorial of a number using iteration
Required Input:
5
Expected Output:
120
Code In Python
def factorial_iterative():
n = 5
# Your code here
return
Output
Click Run Button to view compiled output
22. Find the HCF (Highest Common Factor) of two numbers
Required Input:
8, 12
Expected Output:
4
Code In Python
def find_hcf():
a, b = 8, 12
# Your code here
return
Output
Click Run Button to view compiled output
23. Reverse the digits of a number
Required Input:
12345
Expected Output:
54321
Code In Python
def reverse_digits():
n = 12345
# Your code here
return
Output
Click Run Button to view compiled output
24. Create a dictionary from two lists: one of keys and one of values
Required Input:
['a', 'b', 'c'], [1, 2, 3]
Expected Output:
{'a': 1, 'b': 2, 'c': 3}
Code In Python
def create_dict_from_lists():
keys = ['a', 'b', 'c']
values = [1, 2, 3]
# Your code here
return
Output
Click Run Button to view compiled output
25. Check if two numbers are co-prime (their HCF is 1)
Required Input:
8, 15
Expected Output:
True
Code In Python
def are_coprime():
a, b = 8, 15
# Your code here
return
Output
Click Run Button to view compiled output
26. Find the sum of all positive numbers in a list
Required Input:
[-1, 2, 3, -4, 5]
Expected Output:
10
Code In Python
def sum_of_positives():
lst = [-1, 2, 3, -4, 5]
# Your code here
return
Output
Click Run Button to view compiled output
27. Find all perfect squares between two numbers
Required Input:
1, 100
Expected Output:
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Code In Python
def perfect_squares():
start, end = 1, 100
# Your code here
return
Output
Click Run Button to view compiled output
28. Find the longest common prefix of a list of strings
Required Input:
['flower', 'flow', 'flight']
Expected Output:
fl
Code In Python
def longest_common_prefix():
strs = ['flower', 'flow', 'flight']
# Your code here
return
Output
Click Run Button to view compiled output
29. Find the largest palindrome made from the product of two 2-digit numbers
Required Input:
None
Expected Output:
9009
Code In Python
def largest_palindrome_product():
# Your code here
return
Output
Click Run Button to view compiled output
30. Replace all vowels in a string with the character '*'
Required Input:
hello world
Expected Output:
h*ll* w*rld
Code In Python
def replace_vowels():
s = "hello world"
# Your code here
return
Output
Click Run Button to view compiled output