Practice Questions
Practice Questions
- Krishnan
1. Write a Python program to swap two variables without using a temporary variable.
2. Create a program that takes a user’s input and prints whether the input is a string, integer, or float.
2. Operators
4. Write a program to calculate the area and circumference of a circle given its radius.
5. Create a calculator that can perform addition, subtraction, multiplication, and division based on user input.
6. Write a program to check if two given integers are equal, not equal, or which one is greater using comparison
operators.
3. Control Flow
7. Write a program to find the largest of three numbers using an if-else statement.
8. Create a program that prints all the numbers from 1 to 50, but skips numbers that are divisible by 3.
10. Write a program that prints the Fibonacci series up to a given number using a while loop.
4. Functions
12. Create a function that takes two numbers as input and returns their greatest common divisor (GCD).
13. Write a function that checks whether a given string is a palindrome or not.
14. Create a function that takes a list and returns a new list with unique elements from the original list.
5. Exception Handling
15. Write a program that handles division by zero gracefully by catching exceptions.
16. Create a program that prompts the user to input a number and handle the case when the user inputs a non-
numeric value.
17. Write a program that attempts to open a file that doesn't exist and catches the exception, displaying a user-
friendly message.
19. Create a program that takes a list of words and returns the length of the longest word.
21. Write a Python program to sort a list of tuples based on the second element of each tuple.
https://orion021.github.io/krishnan_t/ 1 | 😁 👻 ✌️ 😎
Python – Practice Questions
7. Loops
22. Write a program to print all prime numbers between 1 and 100 using a for loop.
24. Write a program that repeatedly prompts the user for input until they type "exit".
8. File Handling
25. Write a program to read a text file and count the number of words in the file.
26. Create a program that writes a list of numbers to a file, and then reads and displays the content.
27. Write a program that reads a file and prints the first n lines, where n is provided by the user.
28. Write a program to calculate the square root of a number using the math module.
29. Create a Python program that uses the os module to list all files in a directory.
30. Write a Python script that reads a CSV file using the csv module and prints the contents.
https://orion021.github.io/krishnan_t/ 2 | 😁 👻 ✌️ 😎
Python – Practice Questions
https://orion021.github.io/krishnan_t/ 3 | 😁 👻 ✌️ 😎
Python – Practice Questions
https://orion021.github.io/krishnan_t/ 4 | 😁 👻 ✌️ 😎