【发布时间】:2021-11-20 03:24:21
【问题描述】:
print("Fazli's Vet Services\n")
print("Exam: 50")
print("Vaccinations: 25")
print("Trim Nails: 5")
print("Bath: 20\n")
exam = "exam"
vaccinations = "vaccinations"
trim_nails = "trim nails"
bath = "bath"
none = "none"
exam_price = 50
vaccination_price = 25
trim_nails_price = 5
bath_price = 20
none_price = 0
first_service = input("Select first service:")
second_service = input("Select second service:")
print("\nFazli's Vet Invoice")
if first_service == exam:
print("Service 1 - Exam: " + str(exam_price))
elif first_service == vaccinations:
print("Service 1 - Vaccinations: " + str(vaccination_price))
elif first_service == trim_nails:
print("Service 1 - Trim Nails: " + str(trim_nails_price))
elif first_service == bath:
print("Service 1 - Bath: " + str(bath_price))
elif first_service == none:
print("Service 1 - None " + str(none_price))
else:
print("Service 1 - None " + str(none_price))
if second_service == exam:
print("Service 2 - Exam: " + str(exam_price))
elif second_service == vaccinations:
print("Service 2 - Vaccinations: " + str(vaccination_price))
elif second_service == trim_nails:
print("Service 2 - Trim Nails: " + str(trim_nails_price))
elif second_service == bath:
print("Service 2 - Bath: " + str(bath_price))
elif second_service == none:
print("Service 2 - None " + str(none_price))
else:
print("Service 2 - None " + str(none_price))
上面是我到目前为止的代码。它打印:
Fazli's Vet Services
Exam: 50
Vaccinations: 25
Trim Nails: 5
Bath: 20
Select first service: exam
Select second service: bath
Fazli's Vet Invoice
Service 1 - Exam: 50
Service 2 - Bath: 20
我的目标是让代码将两项服务相加并得出总价格。我的最终目标应该是这样的:
Chanucey's Vet Services
Exam: 45
Vaccinations: 32
Trim Nails: 8
Bath: 15
Select first service: Exam
Select second service: none
Chauncey's Vet Invoice
Service 1 - Exam: 45
Service 2 - None: 0
Total: 45
请注意代码如何添加两个价格并生成“总计”。有什么办法可以做到这一点吗?我是计算机科学专业的初学者,所以我们对 Python 并不太了解。
所有代码都在 Python 中
【问题讨论】:
标签: python conditional-statements