python programs--1
python programs--1
1. Python Basics
- Variables and Data Types:
1. Write a Python program to swap two variables without using a third variable.
2. Create a program to check if a given number is an integer or a float.
3. Write a program to take two float numbers from the user and print their product.
4. How would you convert a boolean value to an integer in Python? Write a program for it.
5. Write a Python program to take a user’s name and age as input, and print a formatted
string displaying the information.
i
- Input/Output:
id
1. Write a program to take a user’s input and print it in reverse.
2. Create a program to prompt the user for two numbers and print their sum.
3. Write a program that takes a sentence as input and prints the number of characters in it.
4. Take a string input from the user and print whether it contains any numbers.
5. Write a program to print the multiplication table of a number given by the user.
gd
- Operators:
1. Write a Python program to perform addition, subtraction, multiplication, and division using
input values.
2. Create a program to find the maximum of three numbers using comparison operators.
3. Write a program to check if a number is divisible by both 5 and 7.
in
4. Create a program that uses bitwise operators to swap two numbers.
5. Write a program to perform logical operations (and, or, not) on two boolean inputs.
- Conditional Statements:
od
- Loops:
1. Write a Python program to print the first 10 natural numbers using a loop.
2. Create a program to find the factorial of a number using a while loop.
3. Write a program that uses a for loop to print the Fibonacci sequence up to 100.
4. Create a program to find the sum of all even numbers between 1 and 50.
5. Write a program to reverse a given string using a loop.
- Functions:
1. Write a Python function to find the greatest common divisor (GCD) of two numbers.
2. Create a function that takes a list of numbers and returns the average.
3. Write a function to check if a string is a palindrome.
4. Create a function that takes two numbers and returns their LCM (Least Common Multiple).
5. Write a function that accepts any number of arguments and returns the sum of all
arguments.
- Exception Handling:
1. Write a program that takes two numbers as input and performs division, handling the case
where the divisor is zero.
2. Create a program that handles file opening exceptions when the file does not exist.
3. Write a program that handles input exceptions when the user enters non-integer data.
4. Create a program that catches exceptions when converting strings to integers.
5. Write a program to raise a custom exception if the input is a negative number.
i
---
id
2. Data Structures
- Lists:
1. Write a Python program to find the second largest number in a list.
gd
2. Create a program to remove duplicates from a list.
3. Write a program to reverse a list without using the `reverse()` method.
4. Create a function to find the average of numbers in a list.
5. Write a program to check if a list is empty or not.
- Tuples:
in
1. Write a Python program to find the index of an element in a tuple.
2. Create a program to convert a list into a tuple.
3. Write a program to find the length of a tuple.
4. Create a program to join two tuples together.
5. Write a program to reverse a tuple.
od
- Sets:
1. Write a Python program to find the union of two sets.
2. Create a program to check if a given set is a subset of another set.
3. Write a program to find the intersection of two sets.
4. Create a program to find the difference between two sets.
C
- Dictionaries:
1. Write a Python program to merge two dictionaries.
2. Create a program to find the key with the maximum value in a dictionary.
3. Write a program to iterate through a dictionary and print all the keys and values.
4. Create a program to check if a key exists in a dictionary.
5. Write a program to remove a specific key from a dictionary.
i
3. Write a program to find the largest element in a list using a linear search.
id
4. Create a program to sort a dictionary by its values.
5. Write a program to sort a list of tuples by the second element in each tuple.
---
gd
3. String Manipulation
- String Operations:
1. Write a Python program to reverse a string without using slicing.
2. Create a program to count the number of vowels in a given string.
3. Write a program to check if a string is a palindrome.
in
4. Create a program to remove all spaces from a string.
5. Write a program to replace all occurrences of a substring in a string.
- String Methods:
1. Write a program to capitalize the first letter of each word in a string.
od
- Regular Expressions:
C
---
4. Functional Programming
- Lambda Functions:
1. Write a lambda function to square a number and use it on a list of numbers.
2. Create a lambda function to return the larger of two numbers.
3. Write a lambda function to filter out even numbers from a list.
4. Create a lambda function to find the cube of a number.
5. Write a program to sort a list of tuples using a lambda function.
i
5. Write a program using `filter()` to remove all negative numbers from a list.
id
- Decorators:
1. Write a decorator to measure the time taken by a function to execute.
2. Create a program to make a function execute twice using a decorator.
gd
3. Write a decorator to print a function’s name every time it is called.
4. Create a program to add authentication before executing a function using a decorator.
5. Write a decorator that capitalizes the output of a function that returns a string.
Follow @codingdidi –
od
Instagram https://www.instagram.com/codingdidi/
Youtube https://youtube.com/@codingdidi?si=TkcPMdGsgV8z61lh
Linkedin www.linkedin.com/in/akansha-yadav24
C