-2
import random
import time
catnames = ['Sprinkes','Pancakes','Captain Meow','Fluffers','Shadow','Kiki','Maxine']
def randomCatName():
catname = random.choice(catnames)
return catname
class SpaceCat:
catmodulesC = []
catmodulesB = []
catmodulesA = []
spaceReady = 1
def __init__(self,name):
self.name = name
def add_catmoduleC(self,a):
self.catmodulesC.append(a)
pass
def add_catmoduleB(self, a):
self.catmodulesB.append(a)
def add_catmoduleA(self, a):
self.catmodulesA.append(a)
return
selected = 0
catC = 0
catB = 0
catA = 0
while True:
da = input("[P]rofile [A]dd Items [I]tems [T]ravel [D]eselect Cat").lower()
if 'p' in da:
if selected == 0:
select = input("Which cat? A,B,C").lower()
if 'a' in select:
nameRandom = randomCatName()
a = SpaceCat(nameRandom)
print("Name: " + a.name)
selected = 1
catA = 1
elif 'b' in select:
nameRandom = randomCatName()
b = SpaceCat(nameRandom)
print("Name: " + b.name)
selected = 1
catB = 1
elif 'c' in select:
nameRandom = randomCatName()
d = SpaceCat(nameRandom)
print("Name: " + b.name)
selected = 1
catC = 1
print("Cat Selected!")
pass
elif 'a' in da:
print("Add items!")
if catC == 0 and catB == 0 and catA == 0:
print("No cat selected! Go to profile")
pass
else:
if catC == 1:
quit = 0
while quit == 0:
d = SpaceCat()
a = input("New Cat Module:")
d.add_catmoduleC(a)
print(d.catmodulesC)
c = input("[E]xit [*]Continue").lower()
if 'e' in c:
quit = 1
if catB == 1:
quit = 0
while quit == 0:
a = input("New Cat Module:")
d.add_catmoduleB(a)
print(d.catmodulesB)
c = input("[E]xit [*]Continue").lower()
if 'e' in c:
quit = 1
if catA == 1:
quit = 0
while quit == 0:
a = input("New Cat Module:")
d.add_catmoduleA(a)
print(d.catmodulesA)
c = input("[E]xit [*]Continue").lower()
if 'e' in c:
quit = 1
elif 'i' in da:
if catA == 1:
if len(d.catmodulesA) == 0:
print("No items in " + d.name)
else:
print(d.catmodulesA)
elif catB == 1:
if len(d.catmodulesB) == 0:
print("No items in " + d.name)
else:
print(d.catmodulesB)
elif catC == 1:
if len(d.catmodulesC) == 0:
print("No items in " + d.name)
else:
print(d.catmodulesC)
else:
print("No Cat selected!")
elif 'd' in da:
if catA == 1:
print("Deslected Cat A!")
selected = 0
catA = 0
elif catB == 1:
print("Deslected Cat B!")
catB = 0
selected = 0
elif catC == 1:
print("Deslected Cat C!")
catC = 0
selected = 0
else:
print("No cat selected!")
運行此代碼時,我輸入'p'選擇配置文件,然後鍵入任何字母a,b或c。但是當我[A] dd項允許我鍵入,但是當我按下輸入時,它說d沒有被定義,我怎樣才能讓它附加我輸入的內容,而不是讓它出錯,它也會出錯任何其他函數涉及d,d未定義,使用類。