[go: up one dir, main page]

0% found this document useful (0 votes)
5 views4 pages

Practice Questions

This document contains a series of Python practice questions organized into categories such as Basic Syntax, Operators, Control Flow, Functions, Exception Handling, Lists, Tuples, Dictionaries, Loops, File Handling, and Modules. Each category includes multiple programming tasks aimed at enhancing Python skills, such as variable swapping, area calculations, prime number checks, and file operations. The questions are designed for learners to practice and improve their coding abilities in Python.

Uploaded by

m.hasham11072005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Practice Questions

This document contains a series of Python practice questions organized into categories such as Basic Syntax, Operators, Control Flow, Functions, Exception Handling, Lists, Tuples, Dictionaries, Loops, File Handling, and Modules. Each category includes multiple programming tasks aimed at enhancing Python skills, such as variable swapping, area calculations, prime number checks, and file operations. The questions are designed for learners to practice and improve their coding abilities in Python.

Uploaded by

m.hasham11072005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Python Practice Questions

- Krishnan

1. Basic Syntax and Data Types

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.

3. Write a program to check whether a given number is even or odd.

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.

9. Write a Python program to check whether a number is prime or not.

10. Write a program that prints the Fibonacci series up to a given number using a while loop.

4. Functions

11. Write a function to find the factorial of a number.

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.

6. Lists, Tuples, and Dictionaries

18. Write a program to find the second largest number in a list.

19. Create a program that takes a list of words and returns the length of the longest word.

20. Write a program to merge two dictionaries into one.

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.

23. Create a multiplication table for numbers 1 to 10 using nested loops.

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.

9. Modules and Packages

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 | 😁 👻 ✌️ 😎

You might also like