0% found this document useful (0 votes)
23 views1 page

Python Data Types and Structures

The document outlines a Python assignment consisting of various tasks, including explanations of mutable vs immutable data types, conditional statements, and the differences between lists and dictionaries. It also includes programming exercises such as creating a set, defining a function to calculate area, creating a class, and handling file exceptions. The assignment must be written on A4 pages or in a notebook and submitted by January 16, 2025.

Uploaded by

fuuny coc
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)
23 views1 page

Python Data Types and Structures

The document outlines a Python assignment consisting of various tasks, including explanations of mutable vs immutable data types, conditional statements, and the differences between lists and dictionaries. It also includes programming exercises such as creating a set, defining a function to calculate area, creating a class, and handling file exceptions. The assignment must be written on A4 pages or in a notebook and submitted by January 16, 2025.

Uploaded by

fuuny coc
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

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.

You might also like