问题
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()
Run this python file. When I run it I get None printed after every print. I don't understand why. I know that when your function in python doesn't have a return it will return None, but I don't understand what is going on here. Any other feed back is great too. Right now I have an object Phone that has a menu and other stuff. Tell me if there's another way you would approach this.
回答1:
Everywhere you see input(print("..."))
, change that to input("...")
. My guess is that it was getting caught up in the print()
function, and would happily print None.
Be sure to also tag this as python3.x, as this is definitely not a 2.x question.
回答2:
it's because of the:
input(print("(1) See your phone specs \n(2) Change information\n Enter a Number: "))
The print() function returns nothing (i.e. None) that gets printed by input(), you don't need to call the print() function, therefore it should look like:
input("(1) See your phone specs \n(2) Change information\n Enter a Number: ")
来源:https://stackoverflow.com/questions/8628317/python-phone-class-printing-none