如何解决此 python 程序中的错误?
How solve error in this python program?
我是 python 的初学者,我有很多很多关于 it.I 试图创建程序但我没有得到结果的问题 exactly.Only 计算很少,剩下的印刷品。
它是这样的:
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 is referenced before assignment" 我在所有允许全局变量的地方都给了它,但仍然没有 come.And 当我得到结果时,finrate 没有得到printed.instead None 或 0 comes.please 让我知道 mistakes.Is 有什么我应该导入的吗?抱歉 trouble.Its 的 class 演示文稿.
感谢您的努力。
totrate=totrate+frate+trate
您已将 totrate 初始化为列表。您不能以这种方式与列表对象进行交互。我相信您想使用 int 类型而不是列表。例如 totrate = 1000
另请注意,这些不是全局变量而是局部变量,因为它们在函数的范围内。
我是 python 的初学者,我有很多很多关于 it.I 试图创建程序但我没有得到结果的问题 exactly.Only 计算很少,剩下的印刷品。
它是这样的:
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 is referenced before assignment" 我在所有允许全局变量的地方都给了它,但仍然没有 come.And 当我得到结果时,finrate 没有得到printed.instead None 或 0 comes.please 让我知道 mistakes.Is 有什么我应该导入的吗?抱歉 trouble.Its 的 class 演示文稿. 感谢您的努力。
totrate=totrate+frate+trate
您已将 totrate 初始化为列表。您不能以这种方式与列表对象进行交互。我相信您想使用 int 类型而不是列表。例如 totrate = 1000
另请注意,这些不是全局变量而是局部变量,因为它们在函数的范围内。