Python Assignment
1. Find the Second Largest Element in a List
Question: Write a function to find the second largest element in a list of numbers.
Input: A list of numbers.
Output: The second largest number.
2. Merge Two Lists Alternately
Question: Write a function that merges two lists by taking elements alternately from
each list.
Input: Two lists of equal length.
Output: A merged list with alternating elements.
3. Check if All Characters are Unique
Question: Write a function to check if all characters in a given string are unique.
Input: A string.
Output: "Unique" or "Not Unique".
4. Count the Frequency of Elements in a List
Question: Write a function to count the frequency of each element in a list.
Input: A list of elements.
Output: A dictionary where keys are elements and values are their frequencies.
5. Find the Missing Number in a Sequence
Question: Write a function to find the missing number in a sequence of numbers from
1 to n.
Input: A list of numbers with one missing element.
Output: The missing number.
6. Sum of Elements in a Tuple
Question: Write a program to calculate the sum of all elements in a tuple.
Input: A tuple of numbers.
Output: The sum of the elements.
7. Find the Longest Word in a Sentence
Question: Write a program to find the longest word in a sentence.
Input: A sentence.
Output: The longest word in the sentence.
8. String Palindrome Check
Question: Write a function to check if a given string is a palindrome.
Input: A string.
Output: "Palindrome" or "Not Palindrome".
9. Temperature Conversion
Question: Write a function to convert temperature between Celsius and Fahrenheit.
Input: A temperature and the unit (C/F).
Output: The converted temperature.
1. Simple Calculator
Question: Write a function-based calculator to perform basic arithmetic operations
(+, -, *, /).
Input: Two numbers and an operator.
Output: The result of the operation.
11. Reverse a String
Question: Write a function to reverse a given string.
Input: A string.
Output: The reversed string.
Requirements: Handle exceptions for non-string inputs.
12. Count Vowels in a String
Question: Write a function to count the number of vowels in a given string.
Input: A string.
Output: The number of vowels.
Requirements: Handle exceptions for non-string inputs.
13. Check Armstrong Number
Question: Write a function to check if a number is an Armstrong number.
Input: An integer.
Output: "Armstrong" or "Not Armstrong".
Requirements: Handle exceptions for non-integer inputs.
14. Generate Multiplication Table
Question: Write a function to generate and print the multiplication table for a given
number.
Input: An integer.
Output: The multiplication table for the number.
Requirements: Handle exceptions for non-integer inputs.
15. Greatest Common Divisor (GCD)
Question: Write a function to find the GCD of two numbers.
Input: Two integers.
Output: The GCD of the two numbers.
Requirements: Handle exceptions for non-integer inputs.
16. Remove Vowels from String
Question: Write a function to remove all vowels from a given string.
Input: A string.
Output: The string without vowels.
Requirements: Handle exceptions for non-string inputs.
17. Merge Two Dictionaries
Question: Write a function to merge two dictionaries into one.
Input: Two dictionaries.
Output: A merged dictionary.
Requirements: Handle exceptions for invalid inputs.
18. Find Maximum Element in List
Question: Write a function to find the maximum element in a list.
Input: A list of numbers.
Output: The maximum number.
19. Calculate Simple Interest
Question: Write a function to calculate simple interest given the principal, rate of
interest, and time.
Input: Three numbers representing principal, rate, and time.
Output: The calculated simple interest..
20. Count Words in a Sentence
Question: Write a function to count the number of words in a given sentence.
Input: A sentence.
Output: The word count.
21. Count Occurrences of a Character
Question: Write a function to count the number of times a specific character appears
in a string.
Input: A string and a character.
Output: The count of occurrences.
22. Find the Unique Elements in a List
Question: Write a function to find all unique elements in a list, excluding duplicates.
Input: A list of elements.
Output: A list of unique elements.
23. Calculate Compound Interest
Question: Write a function to calculate compound interest given the principal, rate of
interest, time, and number of times interest is compounded per year.
Input: Four numbers representing principal, rate, time, and the number of times interest is
compounded per year.
Output: The calculated compound interest.