【发布时间】:2021-06-12 23:31:54
【问题描述】:
我一边上课一边做一些基础练习。其中一个练习使用了 def 函数,我认为他们提供的示例相当不切实际,所以我想把它们放在一起。
print("Welcome to The Car Wash Company")
print("Which service would you like to purchase?")
def wash_car(service):
if (service == 1):
print("Please see the selected products that will be provided to your vehicle")
print("Wash with tri-color foam")
print("Rinse twice")
print("Dry with large blow dryer")
print("Please set your vehicle to neutral and step-off the gas/break pedal at all times")
if (service == 2):
print("Please see the selected products that will be provided to your vehicle")
print("Wash with white foam")
print("Rinse once")
print("Air dry")
print("Please set your vehicle to neutral and step-off the gas/break pedal at all times")
else:
print("Sorry, We do not have the service selected at this time")
print("Try again to choose your service from the Main Menu")
service = input("For Premium press 1... For Standard press 2... ")
if service ==1:
print("Thank you for choosing our Premium car wash service, Please stand by.")
if service == 2:
print("Thank you for choosing our Standard car wash service, Please stand by.")
wash_car(service=1)
print("Thank you for choosing The Car Wash Company as your service provider!")
print("Have a wonderful rest of your day! Come again soon :)")
我遇到的问题是我不知道如何将 1/2 的用户输入定义为选择的服务,以便使用 def Wash_car 函数正确执行。此外,无论输入值如何,我的 else 语句都会触发。
谢谢,
一个新的代码爱好者。
【问题讨论】:
-
能否请您澄清一下“如何将 1/2 的用户输入定义为正确执行的所选服务”的意思?
标签: python python-3.x function syntax