2011-12-25 9 views
2
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ファイルを実行します。私がそれを実行すると、毎回印刷後にNoneが表示されます。なぜか分からない。私は、あなたの関数がPythonで戻り値を持たないときはNoneを返しますが、ここで何が起こっているのか分かりません。他のフィードバックは素晴らしいです。今私は、メニューやその他のものを持っているオブジェクトの電話を持っています。あなたがこれにアプローチする別の方法があるかどうか教えてください。Pythonの電話クラス---印刷なし

input(print("(1) See your phone specs \n(2) Change information\n Enter a Number: ")) 

印刷()関数)の入力(で印刷されます何も(すなわちなし)を返していない、あなたはそれがゆえ、印刷()関数を呼び出す必要はありません:のからだと

答えて

1

:のようになります。私の推測では、それはprint()関数に巻き込まれていて、うれしくNoneを出力します。

これはpython3.xとしてもタグ付けしてください。これは間違いなく2.xの質問です。

+0

ありがとうございました – Jpy

6

あなたがinput(print("..."))を参照してくださいどこinput("...")にそれを変更、

input("(1) See your phone specs \n(2) Change information\n Enter a Number: ")