You are on page 1of 4

Name: Muhammad Izhaan Humayun Roll No: 021

SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY


COMPUTER SCIENCE & INFORMATION TECHNOLOGY DEPARTMENT

Fall 2023
Programming Fundamentals (CS-116T)
Assignment # 2

Semester: 1st Batch: 2023F


Total Marks: 3

CLO # Course Learning Outcomes PLO Mapping Bloom’s Taxonomy


(CLOs)
Apply basic programing concepts. PLO_3 C3
CLO 2
(Problem Analysis) (Applying)

Question 1:

Write a program for a buffet-style restaurant that offers only five basic foods.

 Think of five simple foods and store them in a tuple.


 Use a for loop to print each food the restaurant offers.
 Try to modify one of the items, and make sure that Python rejects the change.
 The restaurant changes its menu, replacing two of the items with different foods. Add a line that
rewrites the tuple, and then use a for loop to print each of the items on the revised menu.

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

elif hours_parked <= 24:

additional_hours = hours_parked - 3

charge = minimum_fee + (additional_hours * additional_hourly_rate)

return min(charge, maximum_daily_charge)

else:

return maximum_daily_charge
Name: Muhammad Izhaan Humayun Roll No: 021
customer1_hours = float(input("Enter hours parked for Customer 1: "))

customer2_hours = float(input("Enter hours parked for Customer 2: "))

customer3_hours = float(input("Enter hours parked for Customer 3: "))

customer1_charge = calculate_charges(customer1_hours)

customer2_charge = calculate_charges(customer2_hours)

customer3_charge = calculate_charges(customer3_hours)

total_receipts = customer1_charge + customer2_charge + customer3_charge

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}")

print("\nTotal Receipts: ${:.2f}".format(total_receipts))

-------------------------------------------------------------------------------------------------------------------

ANSWER 03

def shuffle(lst):

n = len(lst)

for i in range(n - 1, 0, -1):

j = i if i == 2 else i - 1

lst[i], lst[j] = lst[j], lst[i]

return lst

numbers = input("Enter a list of numbers separated by spaces: ").split()

numbers = [int(num) for num in numbers]

shuffled_numbers = shuffle(numbers.copy())

print("Original List:", numbers)


Name: Muhammad Izhaan Humayun Roll No: 021
print("Shuffled List:", shuffled_numbers)

You might also like