Python Interview Questions
Python Interview Questions
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.
Requirements: Handle exceptions for lists with fewer than two elements.
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.
Requirements: Handle exceptions if the lists are of different lengths.
Question: Write a function to check if all characters in a given string are unique.
Input: A string.
Output: "Unique" or "Not Unique".
Requirements: Handle exceptions for non-string inputs.
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.
Requirements: Handle exceptions for lists with no missing elements.
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.
Question: Write a function that converts a list to a set, removing duplicate elements.
Input: A list.
Output: A set with unique elements.
Requirements: Handle exceptions if the input is not a list.
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.
Requirements: Handle exceptions for invalid inputs.
Question: Write a function to check if two strings are anagrams of each other.
Input: Two strings.
Output: "Anagram" or "Not Anagram".
Requirements: Handle exceptions for non-string inputs.
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.
Requirements: Handle exceptions for non-string inputs.
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.
Requirements: Handle exceptions for invalid inputs (e.g., non-list inputs).
Question: Write a function to convert a given string to title case (capitalize the first letter of
each word).
Input: A string.
Output: The string in title case.
Requirements: Handle exceptions for non-string inputs.
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.
Requirements: Handle exceptions for invalid inputs (e.g., negative numbers).