我在编码实践课上遇到了麻烦,这是经典的汽车服务实践。 输出应包括:完整菜单,让用户选择2种服务,以及应提供2种汽车服务客户选择和总价格的汽车店发票
def main():
print("Zooey's (College Fund) Car Shop Services, \nOil change -- $35 \nTire rotation -- $19 \nCar wash -- $7 \nCar wax -- $1 ")
select_svc1 = input("select first service : ")
select_svc2 = input("select second service : ")
if(select_svc1=="-"):
select_svc1="No service"
else:
select_svc1=select_svc1.lower()
if(select_svc1 == "Oil change"):
select_svc1=select_svc1+", $35"
elif(select_svc1 == "Tire rotation"):
select_svc1=select_svc1+", $19"
elif(select_svc1 == "Car wash"):
select_svc1=select_svc1+", $7"
elif(select_svc1 == "Car wax"):
select_svc1=select_svc1+", $12"
if(select_svc2=="-"):
select_svc2="No service"
else:
select_svc2=select_svc2.lower()
if(select_svc2 == "Oil change"):
select_svc2=select_svc2+", $35"
elif(select_svc2 == "Tire rotation"):
select_svc2=select_svc2+", $19"
elif(select_svc2 == "Car wash"):
select_svc2=select_svc2+", $7"
elif(select_svc2 == "Car wax"):
select_svc2=select_svc2+", $12"
print ("\Zooey's (College Fund) Car Shop Services invoice")
print("first service : "+select_svc1)
print("second service : "+select_svc2)
答案 0 :(得分:0)
替代1:
添加:
if __name__ == '__main__':
main()
简而言之,当您运行python模块时,内置变量__name__
的值为'__main__'
。如果导入了模块,则__name__
获取导入的模块的名称。
替代2:
在文件末尾向main()
添加函数调用。
答案 1 :(得分:0)
您正在调用select_svc1=select_svc1.lower()
,然后将其与具有较高字符的字符串进行比较,因此它当然不会做任何事情。要解决此问题,只需删除所有lower()
调用即可。
print("Zooey's (College Fund) Car Shop Services, \nOil change -- $35 \nTire rotation -- $19 \nCar wash -- $7 \nCar wax -- $1 ")
select_svc1 = input("select first service : ")
select_svc2 = input("select second service : ")
if(select_svc1=="-"):
select_svc1="No service"
if(select_svc1 == "Oil change"):
select_svc1=select_svc1+", $35"
elif(select_svc1 == "Tire rotation"):
select_svc1=select_svc1+", $19"
elif(select_svc1 == "Car wash"):
select_svc1=select_svc1+", $7"
elif(select_svc1 == "Car wax"):
select_svc1=select_svc1+", $12"
if(select_svc2=="-"):
select_svc2="No service"
if(select_svc2 == "Oil change"):
select_svc2=select_svc2+", $35"
elif(select_svc2 == "Tire rotation"):
select_svc2=select_svc2+", $19"
elif(select_svc2 == "Car wash"):
select_svc2=select_svc2+", $7"
elif(select_svc2 == "Car wax"):
select_svc2=select_svc2+", $12"
print ("\Zooey's (College Fund) Car Shop Services invoice")
print("first service : "+select_svc1)
print("second service : "+select_svc2)
输出:
Zooey's (College Fund) Car Shop Services,
Oil change -- $35
Tire rotation -- $19
Car wash -- $7
Car wax -- $1
select first service : Oil change
select second service : Car wash
\Zooey's (College Fund) Car Shop Services invoice
first service : Oil change, $35
second service : Car wash, $7