如何解决这个python程序中的错误?
我是python的初学者,我有很多关于它的问题。我试图创建一个程序,但没有得到确切的结果。只有很少的计算,其余的是印刷品 事情是这样的:如何解决这个python程序中的错误?,python,function,output,indentation,Python,Function,Output,Indentation,我是python的初学者,我有很多关于它的问题。我试图创建一个程序,但没有得到确切的结果。只有很少的计算,其余的是印刷品 事情是这样的: def travelmanagement(): trate=[] totrate=[] finrate=[] frate=[] print"WELCOME TO..........MESSAGE" print"ARE YOU A VISITOR OR MEMBER" ch1=raw_input("Enter your choice
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()
缩进是正确的。错误IsToRate在赋值之前被引用。我在所有允许全局变量的地方都给出了它,但它仍然没有出现。当我得到结果时,金额finrate没有被打印出来。相反,没有或0出现。请让我知道错误。有什么我应该导入的吗?抱歉,麻烦了。它是做一个课堂报告。
谢谢你的努力。totrate=totrate+frate+trate 您已将totrate初始化为列表。不能以这种方式与列表对象交互。我相信您希望使用int类型而不是列表。e、 g总计=1000
还要注意的是,它们不是全局变量,而是局部变量,因为它们在函数的作用域中 那个缩进。请更正你的缩进,如果代码看起来像这样,肯定不会运行。你的缩进不正确。将代码粘贴到问题中时,第一行和最后一行前面的空格可能是一个简单的错误,但最后一行:printinvalid之前的空格与代码中的任何if都不匹配。每个级别的缩进应始终为四个空格;否则,您将错过这样的错误,你的代码会让其他人痛苦地阅读,这意味着他们不想帮助你调试它。@Mr.Polywhill我已经回滚了你的编辑,因为至少有一个缩进错误表明OP的代码不能像他们声称的那样运行-这与问题的可回答性有关。尽管事实上在这种情况下,您应该使用而不是。确实如此。您不能以这种方式与列表对象交互。好的,您可以在列表上使用+,只要另一个元素也是列表。但我同意OP应该使用普通INT。