Question: what code can I add to create a loop that allows the customers to select multiple services? and also adds the total for everything selected
what code can I add to create a loop that allows the customers to select multiple services? and also adds the total for everything selected at the end
My code:
# Function to calculate the total cost based on user choice
def calculatetotal:
# Initialize service costs in a dictionary for maintainability
services
B: name: 'Boarding', 'cost':
W: name: 'Walking', 'cost':
D: name: 'Daycare', 'cost':
H: name: 'Homecheck', 'cost':
# Get customer and pet details
customername inputPlease enter your first and last name: strip
petsname inputEnter the name of the pet and type: strip
# Welcome message
printf
Hello customername and petsname
printWelcome To Lisha's Pawsitive Vibes Extended Stay
# Display available services and costs
printOur services and prices:"
for key, value in services.items:
printfkey: valuename $valuecost
# Get user choice of service
servicechoice input
Choose a service Boarding B Walking W Daycare D Homecheck H:
upper
# Initialize total cost
total
# Validate service choice and calculate cost
if servicechoice in services:
quantity intinputfEnter the number of servicesservicechoicenamelower sessionsdaysnights:
total servicesservicechoicecost quantity
else:
printInvalid service choice!"
exit
# Apply military discount if applicable
militarydiscount inputAre you prior or current military yesno: striplower
if militarydiscount "yes":
discountrate # discount
discountamount total discountrate
total discountamount
printfThank you for your service! You received a military discount of $discountamount:f
elif militarydiscount no:
printNo military discount applied."
else:
printInvalid input. Please enter 'yes' or no
exit
# Display the total cost
printf
Your total after discounts is: $total:f
return total
# Function to schedule and repeat dates
def scheduledates:
import datetime
print
Scheduling your service..."
# Get the starting date for the service
startdateinput inputEnter the start date for your service YYYYMMDD: strip
try:
startdate datetime.datetime.strptimestartdateinput, Ymddate
except ValueError:
printInvalid date format! Please use YYYYMMDD
return
# Get the number of days the service repeats
repeatdays intinputEnter the number of days the service will repeat:
# Print out all scheduled dates
print
Here are your scheduled dates:"
for i in rangerepeatdays:
scheduleddate startdate datetime.timedeltadaysi
printfDay i : scheduleddate
# Main function to run the program
def main:
calculatetotal # Calculate service cost and handle discounts
scheduledates # Schedule dates for the service
# Run the program
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
