Python Basics Assignment
1. Variables
● Create a variable `name` to store your name and `age` to store your age. Print them in a
sentence.
● Swap the values of two variables `x` and `y` without using a third variable.
2. Operators
● Write a program that takes two numbers from the user and prints their sum, difference, product,
and quotient.
● Check if a number entered by the user is even or odd using the modulo (%) operator.
3. Conditions
● Write a program to check if a person is eligible to vote (age ≥ 18).
● Ask the user for a number and check: - If it’s positive - If it’s negative - If it’s zero
4. Loops
● Print numbers from 1 to 10 using a `for` loop.
● Print the multiplication table of any number entered by the user.
● Write a program that sums all numbers from 1 to n (user input) using a loop.
5. Functions
● Write a function `greet(name)` that prints 'Hello, !'.
● Write a function `is_prime(n)` that returns True if the number is prime, otherwise False.
6. Lists
● Create a list of 5 fruits and print the second and last fruit.
● Add a new fruit to the list, then remove the first fruit from the list.
● Find the maximum and minimum number in a list of integers.
7. Dictionary
● Create a dictionary with keys: 'name', 'age', 'city' and store your details. Print the dictionary.
● Add a new key 'country' to the dictionary.
● Write a program to count the frequency of each character in a string and store the result in a
dictionary.
8. Set
● Create two sets of numbers and: - Find their union - Find their intersection - Find the difference
between them
● Write a program to remove duplicates from a list using a set.
9. Tuples
● Create a tuple with at least 5 numbers and print the first and last elements.
● Write a program to check if a given element exists in a tuple.
10. Exception Handling
● Write a program to divide two numbers, but handle the ZeroDivisionError.
● Write a program that asks for a number from the user, and handles the case when the user
enters something that is not a number (ValueError).