Professional Documents
Culture Documents
Fall 2023
Programming Fundamentals (CS-116T)
Assignment # 2
Question 1:
Write a program for a buffet-style restaurant that offers only five basic foods.
Question 2:
A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an
additional $0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge
for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time.
Write a program that calculates and prints the parking charges for each of three customers who parked
their cars in this garage yesterday. You should enter the hours parked for each customer. Your program
should print the results in a neat tabular format and should calculate and print the total of yesterday’s
receipts. The program should use the function calculateCharges to determine the charge for each
customer. Your outputs should appear in the following format:
Question 3:
we can shuffle a list using random.shuffle(lst). Write your own function without using
random.shuffle(lst) to shuffle a list and return the list. Use the following function header:
def shuffle(lst):
Write a test program that prompts the user to enter a list of numbers, invokes the function to shuffle the
numbers, and displays the numbers.
Name: Muhammad Izhaan Humayun Roll No: 021
ANSWERS
ANSWER 01
menu = ('Pizza', 'Burger', 'Salad', 'Pasta', 'Soup')
print("Initial Menu:")
for food in menu:
print(food)
try:
menu[0] = 'Sushi'
except TypeError as e:
print(f"Error: {e}\nCannot modify the tuple.")
New_menu = list(menu)
New_menu[0] = 'Sushi'
New_menu[2] = 'Steak'
menu = tuple(New_menu)
print("\nNew Menu:")
for food in menu:
print(food)
---------------------------------------------------------------------------------------------------------------------------------------------------
ANSWER 02
def calculate_charges(hours_parked):
minimum_fee = 2.00
additional_hourly_rate = 0.50
maximum_daily_charge = 10.00
if hours_parked <= 3:
return minimum_fee
additional_hours = hours_parked - 3
else:
return maximum_daily_charge
Name: Muhammad Izhaan Humayun Roll No: 021
customer1_hours = float(input("Enter hours parked for Customer 1: "))
customer1_charge = calculate_charges(customer1_hours)
customer2_charge = calculate_charges(customer2_hours)
customer3_charge = calculate_charges(customer3_hours)
print("\nReceipt Summary")
print("Customer\tHours Parked\tCharge")
print(f"1\t\t{customer1_hours:.2f}\t\t${customer1_charge:.2f}")
print(f"2\t\t{customer2_hours:.2f}\t\t${customer2_charge:.2f}")
print(f"3\t\t{customer3_hours:.2f}\t\t${customer3_charge:.2f}")
-------------------------------------------------------------------------------------------------------------------
ANSWER 03
def shuffle(lst):
n = len(lst)
j = i if i == 2 else i - 1
return lst
shuffled_numbers = shuffle(numbers.copy())