Python Practice Questions
Basic Python-Based Problems and Data Types
- Write a Python program to check if a number is positive, negative, or zero.
- Create a function that takes a string and checks if it's a palindrome.
- Write a program that converts a given temperature from Celsius to Fahrenheit.
- Define a function that calculates the factorial of a number using recursion.
Python Operators, Loops, and Control Flow
- Write a program that prints numbers from 1 to 50, but for multiples of 3, print 'Fizz' instead.
- Write a function that calculates the sum of all odd numbers up to a specified number.
- Create a Python function to check if a number is prime.
- Write a Python program to print the reverse of a given integer.
Tuples, Dictionaries, and Lists
- Write a function that merges two dictionaries by adding values of common keys.
- Given a list of tuples with student names and scores, sort the list by scores.
- Create a function that removes duplicates from a list and returns the unique values.
- Write a Python program to count the occurrences of each character in a given string.
File Handling
- Write a Python program that appends data to an existing file.
- Create a function to count the number of words in a text file.
- Write a Python program to copy content from one file to another.
- Develop a function that reads a CSV file and prints each row as a dictionary.
Exception Handling
- Write a program that takes a list of numbers and calculates their average. Handle cases where the
list is empty.
- Write a Python program to safely perform division and handle any exceptions.
- Define a function that opens a file and prints its contents, with exception handling for file not found.
- Create a function that safely converts a list of strings to integers and handles conversion errors.
Basics of Sorting Algorithms
- Implement the Insertion Sort algorithm to sort a list of numbers.
- Write a function that performs Merge Sort on a given list.
- Develop a Python program to sort a list of dictionaries by a specific key.
- Create a function to perform Quick Sort on a list of integers.
Vectors and Matrices
- Write a Python function that adds two vectors of the same length.
- Create a function to calculate the transpose of a 3x3 matrix.
- Write a program that multiplies a vector by a scalar value.
- Develop a Python program to find the determinant of a 2x2 matrix.
Case Studies
- Baker's Problem: Write a function to calculate ingredient quantities based on batch size.
- Caesar Cipher: Create a decryption function for Caesar cipher.
- Substitution Cipher: Implement a simple substitution cipher with a given key.
- Baker's Problem: Develop a function to estimate baking time based on available ovens.