2016-09-23 85 views
-2

这是我正在做的一件事,在最后一行当我运行我的程序时,它说意外的无意识。我不明白。帮帮我。我正在为课程做一个项目,我无法理解为什么最后一行被忽略掉?

b = 0 
maxpass = 68 
minpass = 0 
fn = "FNO123" 
amount = 0 
seatsremain = 68 - b 

print ("Welcome to Flight Booking Program") 

print ("Please enter the flight number you want to book/cancel with? (Case Sensitve)") 
flight = input() 

while flight != "X": 
    seatsremain = 68 - b 
    while True: 
     if b >= minpass and b <= maxpass: 
      break 
     else: 
      print ("Sorry but the flight you want is currently fully booked. Sorry for Inconviniance") 

    if flight == fn: 
     print ("There are currently", seatsremain, "seats remaining") 
     print ("Would you like to book or cancel your flight?") 
     booking = input().lower() 
    else: 
     print ("ERROR") 
     print ("Not a valid flight number! Remember input is CASE SENSITIVE") 
     print ("Welcome to Flight Booking Program") 
     print ("Please enter the flight number you want to book/cancel with? (Case Sensitve)") 
     flight = input() 

     while True: 
      if booking == "c" or booking == "cancel" or booking == "b" or booking == "book": 
       break 
      else: 
       print ("ERROR") 
       print ("You must cancel at least 1 seat and not exceed the minimum amount of seats avaliable") 
       print ("There are currently", seatsremain, "seats remaining") 
       print ("Would you like to book or cancel your flight?") 

     if booking == "b" or booking == "book": 
      print ("How many seats are you booking?") 
      while True: 
       try: 
        amount = int(input()) 

        if amount <1 or amount >seatsremain: 
         print ("ERROR") 
         print ("You must book at least 1 seat and not exceed the maximum amount of seats avaliable") 
         print ("There are currently", seatsremain, "seats remaining") 
         print ("Would you like to book or cancel your flight?") 
        else: 
         b = b + amount 
         print ("Your flight has been Booked!") 
         print ("Welcome to Flight Booking Program") 
         print ("Please enter the flight number you want to book/cancel with? (Case Sensitve)") 
         flight = input() 
         break 
       except ValueError: 
        print ("You must enter a valid number!") 

     elif booking == "c" or "cancel": 
      print ("How many seats are you canceling?") 
      while True: 
       try: 
        amount = int(input()) 

        if amount <1 or amount >b: 
         print ("ERROR") 
         print ("You must cancel at least 1 seat and not exceed the minimum amount of seats avaliable") 
         print ("There are currently", seatsremain, "seats remaining") 
         print ("Would you like to book or cancel your flight?") 
        else: 
         b = b - amount 
         print ("Your flight has been Cancelled!") 
         print ("Welcome to Flight Booking Program") 
         print ("Please enter the flight number you want to book/cancel with? (Case Sensitve)") 
         flight = input() 
         break 


print("There are", b, "people booked on flight", fn) 
+1

请不要添加乱码来克服限制。如果您的帖子不符合要求,那么您的帖子肯定存在问题。请参见[问]和[mcve] –

+0

只适用于样式...'print'是一个函数。这样你应该写'print(something)'而不是'print(something)'(打印后有空格)。 – pepr

回答

2

你的第二个'尝试'没有'除外'。因为缺少你的最后一行是意想不到的。由于需要'except',因此Python试图找到与try语句缩进相同的东西。

while True: 
    try: 
     amount = int(input()) 

     if amount <1 or amount >b: 
      print ("ERROR") 
      print ("You must cancel at least 1 seat and not exceed the minimum amount of seats avaliable") 
      print ("There are currently", seatsremain, "seats remaining") 
      print ("Would you like to book or cancel your flight?") 
     else: 
      b = b - amount 
      print ("Your flight has been Cancelled!") 
      print ("Welcome to Flight Booking Program") 
      print ("Please enter the flight number you want to book/cancel with? (Case Sensitve)") 
      flight = input() 
      break 
    except ValueError: #<- Add something like this 
     print ("You must enter a valid number!") 
+0

谢谢修复它。 – Bob

相关问题