4CP50: Python Programming
Extra Programs
1. Write a Python class Restaurant with attributes like menu_items, book_table,
and customer_orders, and methods like add_item_to_menu, book_tables, and
customer_order.
Perform the following tasks now:
Now add items to the menu.
Make table reservations.
Take customer orders.
Print the menu.
Print table reservations.
Print customer orders.
Note: Use dictionaries and lists to store the data.
2. Write a Python class BankAccount with attributes like account_number,
balance, date_of_opening and customer_name, and methods like deposit,
withdraw, and check_balance.
3. Write a Python class Inventory with attributes like item_id, item_name,
stock_count, and price, and methods like add_item, update_item, and
check_item_details.
Use a dictionary to store the item details, where the key is the item_id and the
value is a dictionary containing the item_name, stock_count, and price.
4. Write a Python program to create a class named Distance that represents a
distance in feet and inches. The class should have two data members:
feet – to store feet
inches – to store inches
Include a method normalize() that converts extra inches (≥ 12) into feet.
Include a method add() that takes another Distance object, adds it to the
current object, and returns a new Distance object.
Demonstrate the class by creating two Distance objects, adding them, and
printing the total distance.
5. Write a recursive function that inserts the element x at every kth position in the
given list, and returns the modified list.
For example if we wish to insert element 50 at every 3rd position in the
list[1,2,3,4,5,6,7], the output list will be [1,2,3,50,4,5,6,50,7].
6. You are given a list L. Write a program to print first prime number encountered
in the list L.(Treat numbers below and equal to 1 as non-prime)
Input:
[1,2,3,4,5,6,7,8,9]
output:
2
7. Write a Python program to implement a stack data structure using class and
objects, with push, pop, and traversal methods.
8. Write a python program to add two complex numbers by overloading addition
operator.