Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python elif中嵌套的elif语法无效_Python_Python 3.x_If Statement - Fatal编程技术网

Python elif中嵌套的elif语法无效

Python elif中嵌套的elif语法无效,python,python-3.x,if-statement,Python,Python 3.x,If Statement,我目前正在为我的CSE课程做一个项目,我们打算向用户询问他们的租车信息,然后打印出他们的余额和其他信息。每个用户都有预算(B)、每日(D)或每周(W)代码,这些代码都有不同的公式来计算帐户的最终余额。我尝试对每段代码使用if和elif语句,但是在将if语句嵌套到elif语句中时,我不断得到一个无效的语法错误。如何解决此错误以继续处理项目?谢谢大家! answer = input("Would you like to continue? (Y/N)? ") while answer == 'Y'

我目前正在为我的CSE课程做一个项目,我们打算向用户询问他们的租车信息,然后打印出他们的余额和其他信息。每个用户都有预算(B)、每日(D)或每周(W)代码,这些代码都有不同的公式来计算帐户的最终余额。我尝试对每段代码使用if和elif语句,但是在将if语句嵌套到elif语句中时,我不断得到一个无效的语法错误。如何解决此错误以继续处理项目?谢谢大家!

answer = input("Would you like to continue? (Y/N)? ")

while answer == 'Y' or answer == 'y': #user inputs information if they reply yes to the prompt
     customer_code = input("Please enter Customer code (B/D/W): ")
     days_rented = int(input("Please enter the number of days rented: "))
     initial_miles = int(input("Please enter the original mileage of the rental: "))
     final_miles = int(input("Please enter the new mileage of the rental: "))

     mileage = final_miles - initial_miles #calculating other information
     weeks = (days_rented / 7)
     average_miles_d = mileage / days_rented
     average_miles_y = mileage / weeks

     if customer_code == 'B': #budget customer
         balance = ((40 * days_rented) + (.25 * mileage))

     elif customer_code == 'D': #daily customer
         if average_miles_d < 100:
             balance = ((60 * days_rented)    
         elif average_miles_d >= 100:
             balance = ((60 * days_rented) + (.25 * (average_miles - 100)))

     elif customer_code == 'W': #weekly customer
         if average_miles_w < 900:
             balance = (190 * weeks)    
         elif average_miles_w > 900 and average_miles_w < 1500:
             balance = (100 * weeks)    
         else:
             balance = ((200 * weeks) + (.25 * (average_miles_w - 1500))
answer=input(“是否继续?”)
而答案='Y'或答案='Y':#如果用户对提示回答“是”,则输入信息
客户代码=输入(“请输入客户代码(B/D/W):”)
租用天数=int(输入(“请输入租用天数:”)
初始里程=整数(输入(“请输入租金的原始里程:”)
final_miles=int(输入(“请输入租赁的新里程:”)
里程=最终里程-初始里程#计算其他信息
周=(租用天数/7)
平均里程=里程/租用天数
平均英里数=英里数/周
如果客户代码='B':#预算客户
余额=((租用40天)+(租用25英里))
elif客户代码=='D':#每日客户
如果平均里程<100:
余额=((60*天)
elif平均英里数>=100:
余额=((60*天租用)+(.25*(平均英里数-100)))
elif客户代码=='W':#每周客户
如果平均里程<900:
余额=(190*周)
如果平均里程>900且平均里程<1500:
余额=(100*周)
其他:
余额=((200*周)+(.25*(平均英里数-1500))

此行缺少一个
余额=((60*天)Unrelated:weekly customers的代码不能处理
average\u miles\u w==900
。你根本不需要任何括号。给自己找一个好的IDE,比如PyCharm。这会让你很难创建不平衡的括号。添加括号可以解决这个问题,谢谢!