Python - 2 Questions | 40 minutes
INSTRUCTION: Don't look at the answer until you have tried your best to solve the problem. The solution provided here is in case you are stuck in a situation, and you are extremely helpless to solve it out. Hope you will crack the logic. So let's start solving the problem.
TOLLPLAZA
TollPlaza
A toll booth on the way to Bangalore wants to keep the track of the number of vehicles passed through it and total amount collected by them.
Write a python program to implement the class diagram given below.

Class description:
Constructor: Initialize both the instance variables, no_of_vehicle, total_amount to 0
- count_vehicle(): Increment total number of vehicle by 1
- calculate_amount(vehicle_type): Accept vehicle type and identify toll amount for that vehicle based on details given in the table. Add it to the total_amount instance variable.
- collect_toll(owner_type,vehicle_type): Accept owner type and vehicle type of the vehicle for which toll should be collected.
Conditions :
If the owner of the vehicle is a "VIP", then toll amount need not be collected but number of vehicles should be updated.
For any other type of owner, calculate the toll amount and update the number of vehicles.
Perform case insensitive string comparison.
| Vehicle Type | Amount |
| Car | 70 |
| Bus | 100 |
| Truck | 150 |
| Any other type of vehicle | 70 |
(Hint: Invoke appropriate methods to complete the functionality)
Create an object of Tollbooth class, invoke collect_toll() method for different vehicles and test your program.
Note :
Refer Sample Input Output for displaying format
[All text in bold corresponds to the input and the rest corresponds to the output]
Sample Input and Output 1:
Enter the vehicle count :
2
Enter owner type :
VIP
Enter vehicle type :
Car
Enter owner type :
Normal
Enter vehicle type :
Truck
Total No of Vehicle 2
Total amount 150
Sample Input and Output 2:
Enter the vehicle count :
3
Enter owner type :
VIP
Enter vehicle type :
Truck
Enter owner type :
Normal
Enter vehicle type :
Bike
Enter owner type :
Premium
Enter vehicle type :
Bus
Total No of Vehicle 3
Total amount 170
MOBILE ACCESSORIES
Mobile Accessories
The Chennai Mobiles wants to automate its order taking and delivery process of selling mobile accessories.
Write a python program to implement the class diagram given below.
Class Description :
1. mobile_accessory_dict : Static dictionary which stores accessory type (key) and a list (value) which contains the number of items available, price per item and number of days it would take to deliver it.
Initialize it using the sample data given:
{"Case": [750, 200, 5], "Charger": [250, 500, 25], "Headphone": [500, 750, 10], "Powerbank": [150, 800, 30]}
2. Constructor: Initialize attribute, order_date to current date (24/05/2019)
Note : Consider current date is 24/05/2019. Calculate delivery date based on 24/05/2019.
3.calculate_amount(): Calculate and return the total amount to be paid based on the item type and number of items ordered
4. update_stock(): Update stock based on details given below.
- Set the attribute, delivery_date to order_date + number of days required to deliver the ordered item
- Update the number of items available for the ordered item type based on number of items ordered
- If the ordered item type and quantity (no_of_item) are available based on details in mobile_accessory_dic
- Else, return -1
Conditions :
Perform case sensitive string comparison.
If the order item type and quantity is available, display the cost and the delivery date (as given in the sample input and output 1)
If the order item type and quantity is not available, display "Sorry we are out of stock"
(Hint: Invoke appropriate methods to complete the functionality)
Create an object of MobileAccessories class, invoke take_order() method on the MobileAccessories object, display the details and test your program.
Note :
Refer Sample Input Output for displaying format
[All text in bold corresponds to the input and the rest corresponds to the output]
Sample Input and Output 1:
{'Case': [750, 200, 5], 'Charger': [250, 500, 25], 'Powerbank': [150, 800, 30], 'Headphone': [500, 750, 10]}
What do you like to buy :
-Case
-Charger
-Headphone
-Powerbank
Case
Number of Case(s) required :
15
Your order cost Rs.3000 will be delivered by 29/05/2019
Updated Stock Details
{'Powerbank': [150, 800, 30], 'Case': [735, 200, 5], 'Headphone': [500, 750, 10], 'Charger': [250, 500, 25]}
Sample Input and Output 2:
{'Case': [750, 200, 5], 'Charger': [250, 500, 25], 'Powerbank': [150, 800, 30], 'Headphone': [500, 750, 10]}
What do you like to buy :
-Case
-Charger
-Headphone
-Powerbank
Headphone
Number of Headphone(s) required :
1000
Sorry we are out of stock
Comments
Post a Comment