2011-12-25 6 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이 인쇄됩니다. 나는 왜 그런지 이해하지 못한다. 나는 파이썬에서 함수가 반환 값을 갖지 않을 때 None을 리턴하지만, 여기서 무슨 일이 일어나고 있는지 이해하지 못한다. 다른 어떤 피드백도 훌륭합니다. 지금 나는 메뉴와 다른 것들을 가지고있는 객체 폰을 가지고있다. 네가이 문제에 접근하는 또 다른 방법이 있는지 말해봐.파이썬 전화 클래스 --- 인쇄 없음

답변

1

input("...")에 그 변경 :처럼 보일 것입니다. 내 생각에 그것은 print() 함수에 잡혀 있었고 행복하게 None을 출력 할 것입니다.

이 태그는 반드시 2.x 질문이 아니므로 python3.x로 태그를 지정하십시오.

+0

감사합니다. – Jpy

6

이 때문에의이다 :

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

인쇄() 함수는 입력 (인쇄됩니다 아무것도 (즉 없음)을 반환), 당신은, 인쇄() 함수를 호출하는 데, 따라서 필요하지 않습니다 당신이 input(print("..."))을 볼 어디서나

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