class Phone:
def __init__(self):
self.types = ["Touch Screen","Flip", "Slider", "Bar", "Bag"]
self.brand = "No Brand Determined"
self.type_of_phone = "No Type of Phone has been selected"
def get_type(self):
return self.type_of_phone
def change_type(self, changeTo):
if self.check_type(changeTo):
self.type_of_phone = changeTo
else:
print("The Type you wish to change the phone to is not a supported type.")
def change_brand(self, changeTo):
self.brand = changeTo
def check_type(self, inQuestion):
if inQuestion in self.types:
return True
return False
def toString(self):
return "Brand: "+self.brand+"\nType: "+self.type_of_phone+"\n"
def menu(self):
self.intro()
while True:
self.mainScreen()
def intro(self):
print("This program will let you create a cell phone type and brand.")
def mainScreen(self):
option = input(print("(1) See your phone specs \n(2) Change information\n Enter a Number: "))
if option == "1":
print("\n"+self.toString())
elif option == "2":
self.changeScreen()
else:
print("Enter 1 or 2. Please.")
def changeScreen(self):
option = input(print("\nWould you like to change the...\n(1) Type\n(2) Brand\n Enter a Number: "))
if option == "1":
self.changeMyType()
elif option == "2":
self.changeMyBrand()
else:
print("Enter 1 or 2")
self.changeScreen()
def changeMyType(self):
optionType = input(print("\nThese are your options of phones: \n",self.types,"\nEnter an option [case sensitive]: "))
self.change_type(optionType)
def changeMyBrand(self):
optionBrand = input(print("\nEnter the Brand you would like your phone to be: "))
self.change_brand(optionBrand)
def main():
#commands created that fully work:
#Types of Phones to change to: Touch Screen, Flip, Slider, Bar, Bag
#get_type()
#change_type()
myPhone = Phone()
myPhone.menu()
main()
運行這個python文件。當我運行它時,每次打印後都會打印「無」。我不明白爲什麼。我知道,當你的python函數沒有返回時,它將返回None,但我不明白這裏發生了什麼。其他反饋也很棒。現在我有一個對象電話,有一個菜單和其他的東西。告訴我是否有另一種方法可以解決這個問題。Python Phone Class ---打印無
謝謝你的工作 – Jpy 2011-12-29 07:27:34