2015-01-12 57 views
-4

我是一個Python初學者,我有很多很多關於它的問題。我試圖創建一個程序,我沒有完全得到結果。只有很少的計算在那裏,其餘的是印刷品。如何解決這個python程序中的錯誤?

它是這樣的:

def travelmanagement(): 
    trate=[] 
    totrate=[] 
    finrate=[] 
    frate=[] 
    print"WELCOME TO..........MESSAGE" 
    print"ARE YOU A VISITOR OR MEMBER" 
    ch1=raw_input("Enter your choice") 
    V="VISITOR" 
    v="visitor" 
    if(ch1==V)|(ch1==v): 
      print"To proceed further,you need to a create account/use guest session" 
      print"A.Create Account" 
      print"B.Guest Session" 
      ch2=raw_input("Enter your choice") 
      if(ch2=="A")|(ch2=="a"): 
        Name=raw_input("Enter your name:") 
        Username=raw_input("ENter your username") 
        Password=raw_input("ENter your password") 
        Confirm=raw_input("Confirm your password") 
        DOB=raw_input("DD: MM: YY: ") 
        Gender=raw_input("I am....") 
        Mobile=input("Enter your mobile number") 
        Location=raw_input("Enter your current location") 
        print"Prove you are not a robot,Type the text shown below" 
        print"trufle" 
        text="trufle" 
        type=raw_input("Type your text") 
        if(Password==Confirm)&(type==text):#proceed works only after if is satisfied 
             def proceed(): 
              print"You have created account" 
              print"You can now proceed!!" 
              print"Welcome",Username 
              print"TMS specializes in touristplaces" 
              print"P1.DELHI" 
              print"P2.GOA" 
              ch3=raw_input("What's your destination?") 
              pl=['delhi','goa'] 
              t=['t','c','b','p'] 
              gp=[200,400]#general #rate for choosing place 
              gt=[200,300,400,500]#general rate for choosing transportation 
              print"""TMS specializez 
              t.Railways 
              c.Car 
              b.Bus 
              p.Plane""" 
              ch4=raw_input("ENter your choice") 
              if(ch4=="t"):#displays timmings of transportation 
                print"HYPERSONIC HAIRTRIGGER" 
                print "Timmings:" 
                print "DELHI" 
                print ".............." 
                print "GOA" 
                print ".............." 
                print "VELOCIOUS PALACE" 
                print "Timming" 
              if(ch4=="c"): 
                 print"CArs available:" 
                 print"BMW" 
                 print"SWIFT" 
                 print"......." 
                 print"........" 
              if(ch4=="b"): 
                 print"Buses available" 
                 print"................" 
                 print"""delhi 
                 timiings 
                 ......... 
                 goa 

                 ..................""" 

              if(ch4=="p"): 
                 print"""Planes available 
                 ........just like abv""" 
              for i in range(0,2,1): 
                 for j in range(0,4,1): 
                  if(pl[i]==ch3)&(t[j]==ch4): 
                    trate=gp[i]*gt[j] 

              return ch3,ch4  

             def accomodation(): 

                print"""specialises 
                1.place 1 
                a.hotel 1 
                b.hotel 2 
                Hotel1:ac/non ac rooms 
                Ac.for ac... 
                Noac.for non ac.... 
                b.Hotel2 
                Ac.ac.. 
                Noac.non ac... 
                2.place 2 
                a.Hotel1:ac/non ac rooms 
                A.for ac... 
                N.for non ac... 
                b.Hotel2 
                A.ac.. 
                N.non ac...""" 
                genh1=[5000]#general rate for choosing hotel1 
                genh2=[4000]#general rate for choosing hotel2 
                ch5=input("Enter ypur choice") 
                fav=raw_input("ENter hotel choice") 
                mode=raw_input("Enter ac/no ac") 
                TAc=[1000]#rate for ac room 
                Nac=[400]#rate for non ac room 
                if(ch5==1): 
                 if(fav=="a"): 
                  if(mode=="Ac"): 
                   frate=genh1+TAc 
                  else: 
                    frate=genh1+Nac 
                 elif(fav=="b"): 
                   if(mode=="Ac"): 
                    frate=genh2+TAc 
                   else: 
                    frate=genh2+Nac 
                elif(ch5==2): 
                  if(fav=="a"): 
                   if(mode=="Ac"): 
                    frate=genh1+TAc 
                   else: 
                    frate=genh1+Nac 
                  if(fav=="b"): 
                   if(mode=="Ac"): 
                    frate=genh2+TAc 
                   else: 
                    frate=genh2+Nac 
                else: 
                  totrate=totrate+frate+trate 
                print"Due to prefer a guide??" 
                print"a guide inperson...rate=1000" 
                print"maps,3g....rate=2000" 
                ch6=raw_input("ENter your choice") 
                if(ch6=="person")|(ch6=="PERSON"): 
                 totrate=totrate+[1000] 
                elif(ch6=="gadget"|ch6=="GADGET"): 
                 totrate=totrate+[2000] 
                else: 
                 return totrate 


             x=proceed() 
             y=accomodation() 
             print x 
             print y 
         else: 
          print"invalid" 


       #if(ch1==b) is present after this.Same lines as above is repeated 
travelmanagement() 

縮進proper.The錯誤「totrate被分配之前引用的」我把它在全局變量是允許所有的地方,但仍當我犯規come.And得到結果的金額finrate沒有得到印刷。但沒有或0來。請讓我知道的錯誤。是否有東西我應該導入??對不起,麻煩,它爲一個類的演示文稿。 感謝您的努力。

+12

縮進。 – Christian

+3

請更正您的縮進,如果看起來像這樣,您的代碼肯定不會運行。 –

+0

您的縮進是**不是**「正確的」。也許第一行和最後一行前面的空格在將代碼粘貼到您的問題中時是一個簡單的錯誤,但最後一個'else:'(在'print「無效」''之前)與代碼中的任何'if'都不匹配。縮進應該總是**每個級別四個空格;否則,你會錯過這樣的錯誤,並且你的代碼會讓其他人閱讀時感到痛苦(這意味着他們不想幫你調試它)。 –

回答

0

totrate = totrate + Frate的+ trate

已初始化totrate是一個列表。你不能以這種方式與列表對象交互。我相信你想要使用int類型而不是列表。例如totrate = 1000

還要注意,這些不是全局變量,而是局部變量,因爲它們在函數的範圍內。

+0

_「你不能用這種方式與列表對象進行交互。」___只要另一個元素也是一個列表,你就可以在列表上使用「+」。但我同意OP應該使用普通整數。 – Kevin