0% found this document useful (0 votes)
39 views

Lab 05

1. The document contains 5 questions that ask the student to write Python programs to perform various tasks involving dictionaries, tuples, lists, classes, inheritance, and properties. 2. The tasks include merging dictionaries, accessing values, initializing dictionaries with defaults, unpacking tuples, creating classes with and without attributes/methods, inheriting from parent classes, defining class attributes, and overriding methods. 3. Expected outputs are provided for testing the programs.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Lab 05

1. The document contains 5 questions that ask the student to write Python programs to perform various tasks involving dictionaries, tuples, lists, classes, inheritance, and properties. 2. The tasks include merging dictionaries, accessing values, initializing dictionaries with defaults, unpacking tuples, creating classes with and without attributes/methods, inheriting from parent classes, defining class attributes, and overriding methods. 3. Expected outputs are provided for testing the programs.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Question 1 (2 marks): Write a program to perform these tasks:

1. Merge two Python dictionaries into one

2. Print the value of key ‘history’ from the below dict

3. Initialize dictionary with default values

Question 2 (1 marks): Write a program to perform these tasks:

1. Access value 20 from the tuple


2. Unpack the tuple into 4 variables

Question 3 (2 marks): Write a program to perform these tasks:

1. Creating a list in PythonCreate a Class with instance attributes

Write a Python program to create a Vehicle class with max_speed and mileage instance


attributes.

Expected Output:

2. Create a Vehicle class without any variables and methods

Question 4 (2.5 marks): Write a program to perform these tasks:

1. Create a child class Bus that will inherit all of the variables and methods of the
Vehicle class
Expected Output:

2. Class Inheritance

Create a Bus class that inherits from the Vehicle class. Give the capacity argument
of Bus.seating_capacity() a default value of 50.

Use the following code for your parent Vehicle class.

Expected Output:

Question 5 (2.5 marks): Write a program to perform these tasks:

4. Define a property that must have the same value for every class instance (object)

Define a class attribute”color” with a default value white. I.e., Every Vehicle should


be white.

Use the following code for this exercise.


Expected Output:

5. Class Inheritance

Given:

Create a Bus child class that inherits from the Vehicle class. The default fare charge of
any vehicle is seating capacity * 100. If Vehicle is Bus instance, we need to add an extra
10% on full fare as a maintenance charge. So total fare for bus instance will become
the final amount = total fare + 10% of the total fare.

Note: The bus seating capacity is 50. so the final fare amount should be 5500. You need to
override the fare() method of a Vehicle class in Bus class.

Use the following code for your parent Vehicle class. We need to access the parent class
from inside a child class method.

Expected Output:

You might also like