Week 1 Assignment
Week 1 Assignment
Variant 1: Library Member Tracker
A community library tracks members, their borrowed books, and a shared membership counter.
- Define a class
LibraryMemberwith class variables:library_name = "City Library"andtotal_members = 0. - Define
__init__with parametersname, member_id, borrowed=None:- Store
self.nameandself.member_id. - Use the None default pattern to initialize
self.borrowedas a list. - Increment
LibraryMember.total_membersby 1.
- Store
- Create a method
borrow_bookwith parametertitle:- If
titleis a non-empty string, append it toself.borrowedand print"Borrowed: {title}".
- If
- Create a method
return_bookwith parametertitle:- If
titleexists inself.borrowed, remove it and print"Returned: {title}". - Otherwise print
"Book not found".
- If
- Create a method
display_memberthat prints"Member: {name} ({member_id}) at {library_name}". - Create two members using the test data and perform the listed operations.
- Print the total members count as
"Total members: {count}".
Input
Member 1: name="Aziza", member_id="L-101"
Member 2: name="Bekzod", member_id="L-102"
Operations:
- Display Aziza's info
- Aziza borrows "1984"
- Aziza borrows "Dune"
- Aziza returns "Dune"
- Display Bekzod's info
- Bekzod returns "Foundation"
Expected Output
Member: Aziza (L-101) at City Library
Borrowed: 1984
Borrowed: Dune
Returned: Dune
Member: Bekzod (L-102) at City Library
Book not found
Total members: 2
Variant 2: Fitness Class Enrollment
A gym manages class enrollments with capacity limits and shared scheduling data.
- Define a class
FitnessClasswith class variables:gym_name = "Power Gym",max_capacity = 3, andtotal_classes = 0. - Define
__init__with parametersclass_name, instructor:- Store
self.class_nameandself.instructor. - Initialize
self.participantsas an empty list. - Increment
FitnessClass.total_classesby 1.
- Store
- Create a method
add_participantwith parametername:- If the class is not full, append the name and print
"Added {name} to {class_name}". - If full, print
"Class is full".
- If the class is not full, append the name and print
- Create a method
remove_participantwith parametername:- If
nameis inself.participants, remove it and print"Removed {name} from {class_name}". - Otherwise print
"Participant not found".
- If
- Create a method
display_classthat prints"Class: {class_name}, Instructor: {instructor}, Gym: {gym_name}". - Create one class and perform the listed operations.
- Print total classes as
"Total classes: {count}".
Input
Class: "Yoga", Instructor: "Malika"
Operations:
- Display class info
- Add "Ali"
- Add "Vali"
- Add "Gulnora"
- Add "Rustam" (should fail - full)
- Remove "Vali"
- Remove "Sarvar" (not enrolled)
Expected Output
Class: Yoga, Instructor: Malika, Gym: Power Gym
Added Ali to Yoga
Added Vali to Yoga
Added Gulnora to Yoga
Class is full
Removed Vali from Yoga
Participant not found
Total classes: 1
Variant 3: Digital Wallet
A digital wallet tracks balance, transaction history, and shared limits across all wallets.
- Define a class
DigitalWalletwith class variables:service_name = "PayWay",min_balance = 0, andtotal_wallets = 0. - Define
__init__with parametersowner, balance=0, history=None:- Store
self.ownerandself.balance. - Initialize
self.historyusing the None default pattern. - Increment
DigitalWallet.total_walletsby 1.
- Store
- Create a method
add_fundswith parameteramount:- If
amount > 0, add it toself.balance, record"+{amount}"in history, and print"Added {amount}. Balance: {balance}".
- If
- Create a method
spendwith parameteramount:- If
self.balance - amount >= DigitalWallet.min_balance, subtract, record"-{amount}"in history, and print"Spent {amount}. Balance: {balance}". - Otherwise print
"Insufficient balance".
- If
- Create a method
display_walletthat prints"Owner: {owner}, Balance: {balance}, Service: {service_name}". - Create a method
show_historythat prints each entry inself.historyon a new line. - Create one wallet and perform the listed operations.
- Print total wallets as
"Total wallets: {count}".
Input
Wallet: owner="Umida", balance=40
Operations:
- Display wallet info
- Add 25
- Spend 50
- Spend 10
- Show history
Expected Output
Owner: Umida, Balance: 40, Service: PayWay
Added 25. Balance: 65
Spent 50. Balance: 15
Spent 10. Balance: 5
+25
-50
-10
Total wallets: 1
Variant 4: Pet Hotel Guest System
A pet hotel tracks animals staying at the facility, managing check-ins and check-outs with a shared guest counter.
- Define a class
PetGuestwith class variables:hotel_name = "Paws & Relax Hotel"andtotal_guests = 0. - Define
__init__with parameterspet_name, owner_id, toys=None:- Store
self.pet_nameandself.owner_id. - Use the None default pattern to initialize
self.toysas a list. - Increment
PetGuest.total_guestsby 1.
- Store
- Create a method
add_toywith parametertoy_name:- If
toy_nameis a non-empty string, append it toself.toysand print"Added toy: {toy_name}".
- If
- Create a method
remove_toywith parametertoy_name:- If
toy_nameexists inself.toys, remove it and print"Removed toy: {toy_name}". - Otherwise print
"Toy not found".
- If
- Create a method
display_guestthat prints"Guest: {pet_name} (Owner: {owner_id}) at {hotel_name}". - Create two guests using the test data and perform the listed operations.
- Print the total guests count as
"Total guests: {count}".
Input
Guest 1: pet_name="Mittens", owner_id="P-201"
Guest 2: pet_name="Rex", owner_id="P-202"
Operations:
- Display Mittens' info
- Mittens adds "Ball"
- Mittens adds "Mouse"
- Mittens removes "Mouse"
- Display Rex's info
- Rex removes "Bone"
Expected Output
Guest: Mittens (Owner: P-201) at Paws & Relax Hotel
Added toy: Ball
Added toy: Mouse
Removed toy: Mouse
Guest: Rex (Owner: P-202) at Paws & Relax Hotel
Toy not found
Total guests: 2
Variant 5: Restaurant Table Manager
A restaurant manages table seating with capacity limits and tracks total tables in the establishment.
- Define a class
RestaurantTablewith class variables:restaurant_name = "Taste of Tashkent",max_seats = 4, andtotal_tables = 0. - Define
__init__with parameterstable_number, section:- Store
self.table_numberandself.section. - Initialize
self.dinersas an empty list. - Increment
RestaurantTable.total_tablesby 1.
- Store
- Create a method
seat_dinerwith parametername:- If the table is not full, append the name and print
"Seated {name} at Table {table_number}". - If full, print
"Table is full".
- If the table is not full, append the name and print
- Create a method
unseat_dinerwith parametername:- If
nameis inself.diners, remove it and print"Removed {name} from Table {table_number}". - Otherwise print
"Diner not found".
- If
- Create a method
display_tablethat prints"Table {table_number} in {section} at {restaurant_name}". - Create one table and perform the listed operations.
- Print total tables as
"Total tables: {count}".
Input
Table: 5, Section: "Patio"
Operations:
- Display table info
- Seat "Nodira"
- Seat "Kamola"
- Seat "Farhod"
- Seat "Shavkat"
- Seat "Dilshod" (should fail - full)
- Unseat "Kamola"
- Unseat "Zafar" (not seated)
Expected Output
Table 5 in Patio at Taste of Tashkent
Seated Nodira at Table 5
Seated Kamola at Table 5
Seated Farhod at Table 5
Seated Shavkat at Table 5
Table is full
Removed Kamola from Table 5
Diner not found
Total tables: 1
Variant 6: Bus Pass Tracker
A transit system tracks passenger rides using a stored-value pass system with fare history and shared minimum balance rules.
- Define a class
BusPasswith class variables:transit_name = "Tashkent Metro",min_fare = 3, andtotal_passes = 0. - Define
__init__with parametersholder, balance=0, rides=None:- Store
self.holderandself.balance. - Initialize
self.ridesusing the None default pattern. - Increment
BusPass.total_passesby 1.
- Store
- Create a method
load_passwith parameteramount:- If
amount > 0, add it toself.balance, record"+{amount}"in rides, and print"Loaded {amount}. Balance: {balance}".
- If
- Create a method
take_ridewith parameterfare:- If
self.balance - fare >= BusPass.min_fare, subtract fare, record"-{fare}"in rides, and print"Charged {fare}. Balance: {balance}". - Otherwise print
"Insufficient balance for ride".
- If
- Create a method
display_passthat prints"Holder: {holder}, Balance: {balance}, Transit: {transit_name}". - Create a method
show_ridesthat prints each entry inself.rideson a new line. - Create one pass and perform the listed operations.
- Print total passes as
"Total passes: {count}".
Input
Pass: holder="Jamshid", balance=10
Operations:
- Display pass info
- Load 20
- Take ride costing 5
- Take ride costing 8
- Show rides
Expected Output
Holder: Jamshid, Balance: 10, Transit: Tashkent Metro
Loaded 20. Balance: 30
Charged 5. Balance: 25
Charged 8. Balance: 17
+20
-5
-8
Total passes: 1
Variant 7: School Locker Management
A school tracks locker usage, allowing students to store and retrieve items with a shared locker counter.
- Define a class
SchoolLockerwith class variables:school_name = "Al-Khwarizmi Academy"andtotal_lockers = 0. - Define
__init__with parametersstudent_name, locker_id, items=None:- Store
self.student_nameandself.locker_id. - Use the None default pattern to initialize
self.itemsas a list. - Increment
SchoolLocker.total_lockersby 1.
- Store
- Create a method
store_itemwith parameteritem_name:- If
item_nameis a non-empty string, append it toself.itemsand print"Stored: {item_name}".
- If
- Create a method
retrieve_itemwith parameteritem_name:- If
item_nameexists inself.items, remove it and print"Retrieved: {item_name}". - Otherwise print
"Item not found".
- If
- Create a method
display_lockerthat prints"Locker {locker_id} assigned to {student_name} at {school_name}". - Create two lockers using the test data and perform the listed operations.
- Print the total lockers count as
"Total lockers: {count}".
Input
Locker 1: student_name="Gulnora", locker_id="A-12"
Locker 2: student_name="Ravshan", locker_id="A-15"
Operations:
- Display Gulnora's locker info
- Gulnora stores "Calculator"
- Gulnora stores "Notebook"
- Gulnora retrieves "Calculator"
- Display Ravshan's locker info
- Ravshan retrieves "Backpack"
Expected Output
Locker A-12 assigned to Gulnora at Al-Khwarizmi Academy
Stored: Calculator
Stored: Notebook
Retrieved: Calculator
Locker A-15 assigned to Ravshan at Al-Khwarizmi Academy
Item not found
Total lockers: 2
Variant 8: Parking Lot Spot Manager
A parking facility manages vehicle spots with capacity limits and tracks total available spots.
- Define a class
ParkingSpotwith class variables:lot_name = "City Center Parking",max_vehicles = 3, andtotal_spots = 0. - Define
__init__with parametersspot_number, level:- Store
self.spot_numberandself.level. - Initialize
self.vehiclesas an empty list. - Increment
ParkingSpot.total_spotsby 1.
- Store
- Create a method
park_vehiclewith parameterplate:- If the spot is not full, append the plate and print
"Parked vehicle {plate} at Spot {spot_number}". - If full, print
"Spot is full".
- If the spot is not full, append the plate and print
- Create a method
remove_vehiclewith parameterplate:- If
plateis inself.vehicles, remove it and print"Removed vehicle {plate} from Spot {spot_number}". - Otherwise print
"Vehicle not found".
- If
- Create a method
display_spotthat prints"Spot {spot_number} on Level {level} at {lot_name}". - Create one spot and perform the listed operations.
- Print total spots as
"Total spots: {count}".
Input
Spot: 42, Level: "B2"
Operations:
- Display spot info
- Park "AA 123"
- Park "BB 456"
- Park "CC 789"
- Park "DD 000" (should fail - full)
- Remove "BB 456"
- Remove "ZZ 999" (not parked)
Expected Output
Spot 42 on Level B2 at City Center Parking
Parked vehicle AA 123 at Spot 42
Parked vehicle BB 456 at Spot 42
Parked vehicle CC 789 at Spot 42
Spot is full
Removed vehicle BB 456 from Spot 42
Vehicle not found
Total spots: 1
Variant 9: Cafeteria Meal Card
A cafeteria tracks student meal balances with transaction history and a minimum required balance.
- Define a class
MealCardwith class variables:cafeteria_name = "Campus Cafe",min_balance = 5, andtotal_cards = 0. - Define
__init__with parametersstudent, balance=0, transactions=None:- Store
self.studentandself.balance. - Initialize
self.transactionsusing the None default pattern. - Increment
MealCard.total_cardsby 1.
- Store
- Create a method
depositwith parameteramount:- If
amount > 0, add it toself.balance, record"+{amount}"in transactions, and print"Deposited {amount}. Balance: {balance}".
- If
- Create a method
purchasewith parameteramount:- If
self.balance - amount >= MealCard.min_balance, subtract, record"-{amount}"in transactions, and print"Purchased meal for {amount}. Balance: {balance}". - Otherwise print
"Insufficient balance for purchase".
- If
- Create a method
display_cardthat prints"Student: {student}, Balance: {balance}, Cafeteria: {cafeteria_name}". - Create a method
show_transactionsthat prints each entry inself.transactionson a new line. - Create one card and perform the listed operations.
- Print total cards as
"Total cards: {count}".
Input
Card: student="Malika", balance=15
Operations:
- Display card info
- Deposit 30
- Purchase meal for 12
- Purchase meal for 10
- Show transactions
Expected Output
Student: Malika, Balance: 15, Cafeteria: Campus Cafe
Deposited 30. Balance: 45
Purchased meal for 12. Balance: 33
Purchased meal for 10. Balance: 23
+30
-12
-10
Total cards: 1
Variant 10: Music Studio Booking
A music studio tracks artists and their booked equipment with a shared booking counter.
- Define a class
StudioBookingwith class variables:studio_name = "Harmony Studios"andtotal_bookings = 0. - Define
__init__with parametersartist_name, session_id, equipment=None:- Store
self.artist_nameandself.session_id. - Use the None default pattern to initialize
self.equipmentas a list. - Increment
StudioBooking.total_bookingsby 1.
- Store
- Create a method
book_equipmentwith parameteritem_name:- If
item_nameis a non-empty string, append it toself.equipmentand print"Booked equipment: {item_name}".
- If
- Create a method
return_equipmentwith parameteritem_name:- If
item_nameexists inself.equipment, remove it and print"Returned equipment: {item_name}". - Otherwise print
"Equipment not booked".
- If
- Create a method
display_bookingthat prints"Session {session_id} for {artist_name} at {studio_name}". - Create two bookings using the test data and perform the listed operations.
- Print the total bookings count as
"Total bookings: {count}".
Input
Booking 1: artist_name="Daler", session_id="M-501"
Booking 2: artist_name="Nargiza", session_id="M-502"
Operations:
- Display Daler's booking info
- Daler books "Guitar"
- Daler books "Microphone"
- Daler returns "Microphone"
- Display Nargiza's booking info
- Nargiza returns "Drums"
Expected Output
Session M-501 for Daler at Harmony Studios
Booked equipment: Guitar
Booked equipment: Microphone
Returned equipment: Microphone
Session M-502 for Nargiza at Harmony Studios
Equipment not booked
Total bookings: 2
Variant 11: Cinema Hall Seating
A cinema manages theater seating with capacity limits and tracks total halls.
- Define a class
CinemaHallwith class variables:cinema_name = "Silver Screen",max_viewers = 5, andtotal_halls = 0. - Define
__init__with parametershall_number, movie_title:- Store
self.hall_numberandself.movie_title. - Initialize
self.viewersas an empty list. - Increment
CinemaHall.total_hallsby 1.
- Store
- Create a method
seat_viewerwith parametername:- If the hall is not full, append the name and print
"Seated {name} in Hall {hall_number}". - If full, print
"Hall is full".
- If the hall is not full, append the name and print
- Create a method
remove_viewerwith parametername:- If
nameis inself.viewers, remove it and print"Removed {name} from Hall {hall_number}". - Otherwise print
"Viewer not found".
- If
- Create a method
display_hallthat prints"Hall {hall_number} showing {movie_title} at {cinema_name}". - Create one hall and perform the listed operations.
- Print total halls as
"Total halls: {count}".
Input
Hall: 3, Movie: "Inception"
Operations:
- Display hall info
- Seat "Aziz"
- Seat "Bobur"
- Seat "Charos"
- Seat "Dilshod"
- Seat "Eldor"
- Seat "Feruza" (should fail - full)
- Remove "Bobur"
- Remove "Gulnora" (not seated)
Expected Output
Hall 3 showing Inception at Silver Screen
Seated Aziz in Hall 3
Seated Bobur in Hall 3
Seated Charos in Hall 3
Seated Dilshod in Hall 3
Seated Eldor in Hall 3
Hall is full
Removed Bobur from Hall 3
Viewer not found
Total halls: 1
Variant 12: Tool Rental System
A hardware store manages tool rentals with balance tracking and rental history.
- Define a class
ToolRentalwith class variables:shop_name = "BuildIt Hardware",min_deposit = 10, andtotal_rentals = 0. - Define
__init__with parametersrenter, deposit=0, history=None:- Store
self.renterandself.deposit. - Initialize
self.historyusing the None default pattern. - Increment
ToolRental.total_rentalsby 1.
- Store
- Create a method
add_depositwith parameteramount:- If
amount > 0, add it toself.deposit, record"+{amount}"in history, and print"Added deposit {amount}. Total: {deposit}".
- If
- Create a method
rent_toolwith parameterfee:- If
self.deposit - fee >= ToolRental.min_deposit, subtract fee, record"-{fee}"in history, and print"Rented tool for {fee}. Remaining: {deposit}". - Otherwise print
"Insufficient deposit for rental".
- If
- Create a method
display_rentalthat prints"Renter: {renter}, Deposit: {deposit}, Shop: {shop_name}". - Create a method
show_historythat prints each entry inself.historyon a new line. - Create one rental and perform the listed operations.
- Print total rentals as
"Total rentals: {count}".
Input
Rental: renter="Shokir", deposit=20
Operations:
- Display rental info
- Add deposit 40
- Rent tool costing 15
- Rent tool costing 25
- Show history
Expected Output
Renter: Shokir, Deposit: 20, Shop: BuildIt Hardware
Added deposit 40. Total: 60
Rented tool for 15. Remaining: 45
Rented tool for 25. Remaining: 20
+40
-15
-25
Total rentals: 1
This content will be available starting February 13, 2026.