ECE181: PRACTICE SHEET: 2
FUNCTIONS and STRINGS
a) Problem Statements on Functions in Python
1. Problem: Write a function to find the maximum of three numbers.
2. Problem: Create a function that calculates the factorial of a given number.
3. Problem: Define a function that checks if a number is prime.
4. Problem: Write a function to calculate the sum of all numbers in a list.
5. Problem: Implement a function that returns the nth Fibonacci number.
6. Problem: Write a function that accepts a string and returns the number of vowels in
the string.
7. Problem: Create a function that reverses a list without using slicing.
8. Problem: Define a function to check if a string is a palindrome.
9. Problem: Write a function to convert temperature from Celsius to Fahrenheit.
10. Problem: Create a function that checks if two strings are anagrams.
11. Problem: Define a function that calculates the greatest common divisor (GCD) of
two numbers.
12. Problem: Write a function to count the occurrences of a particular element in a list.
13. Problem: Create a function that finds the smallest number in a list of numbers.
14. Problem: Write a function to return the sum of squares of the first n natural numbers.
15. Problem: Define a function that accepts a list of numbers and returns a new list with
all duplicates removed.
(b) Problem Statements on String Methods in Python
1. Problem: Write a program to count the number of uppercase and lowercase letters in
a string using string methods.
2. Problem: Create a program that checks if a string starts with a particular substring.
3. Problem: Write a program to find and replace all occurrences of a word in a given
string.
4. Problem: Implement a program that checks if a string ends with a certain suffix.
5. Problem: Write a program to convert a string to title case (where the first letter of
each word is capitalized).
6. Problem: Create a program to remove all leading and trailing spaces from a string.
7. Problem: Write a program to find the index of the first occurrence of a substring in a
string.
8. Problem: Implement a program to split a string into a list of words.
9. Problem: Write a program to count the number of occurrences of a character in a
string.
10. Problem: Create a program to join a list of words into a single string with a space as
the separator.
11. Problem: Write a program that converts a given string into all uppercase letters.
12. Problem: Implement a program to check if a string is numeric using string methods.
13. Problem: Write a program to reverse the words in a sentence using string methods.
14. Problem: Create a program that replaces all vowels in a string with asterisks (*).
15. Problem: Write a program to check if two strings are equal, ignoring case sensitivity.