Python assignment
1.1 Explain the difference between mutable and immutable data types in Python.
Give two examples of each type.
1.2 What are `if`, `elif`, and `else` statements in Python?
Provide an example of when you would use these statements in a program
1.3 What is the difference between a list and a dictionary in Python?
Highlight one scenario where each would be more useful than the other.
1.4 Write a Python program to:
- Create a set of your favorite three colors.
- Add one more color to the set.
- Create a tuple containing the names of the days of the week.
- Access and print the third day in the tuple.
2.1 Write a Python function called `calculate_area` that:
- Accepts two arguments: `length` and `width`.
- Returns the area of a rectangle using these dimensions.
- Call the function with `length=5` and `width=3`, and print the result.
2.2 Define a class `Person` with the following:
- Attributes: `name`, `age`
- A method `introduce` that prints: "Hello, my name is [name] and I am [age] years
old."
- Create an object of the class and call the `introduce` method.
2.3 Write a Python program that:
- Tries to read a file called `[Link]`.
- If the file does not exist, catch the exception and print "File not found."
- If the file exists, read and print its contents.
Instructions:
1. Write all the questions in A4 pages or notebook.
2. Submit your assignment by 16/01/2025.