I made a simple program where animals make sounds. However, it prints none after each line in the shell. Is there something that should be change in the coding where the text is printed? or do I have to strip the text of anything?
Here is an example :
I am a Dog
None
Woof! Woof!
None
My code is:
import pets
def main():
print "Choose number to hear what sound the animal makes."
print "1. Enter choice"
print "2. Dog"
print "3. Cat"
print "4. Bird"
print "5. Quit program"
choice = input("Choice: ")
while choice != 5:
if choice == 1:
species = raw_input("Input an animal: ")
userchoice = pets.Pet(species)
print userchoice.show_species()
print userchoice.make_sound()
choice = input("Choice: ")
elif choice == 2:
userchoice = pets.Dog()
print userchoice.show_species()
print userchoice.make_sound()
choice = input("Choice: ")
elif choice == 3:
userchoice = pets.Cat()
print userchoice.show_species()
print userchoice.make_sound()
choice = input("Choice: ")
elif choice == 4:
userchoice = pets.Bird()
print userchoice.show_species()
print userchoice.make_sound()
choice = input("Choice: ")
else:
print "Error"
choice = input("Choice: ")
main()
the module imported is
class Pet:
def __init__(self,species):
self.__species = species
def show_species(self):
print "I am a ", self.__species
def make_sound(self):
print "I do not make a sound."
class Dog(Pet):
def __init__(self):
Pet.__init__(self, "Dog")
def make_sound(self):
print "Woof! Woof!"
class Bird(Pet):
def __init__(self):
Pet.__init__(self, "Bird")
def make_sound(self):
print "Chirp! Chirp!"
class Cat(Pet):
def __init__(self):
Pet.__init__(self, "Cat")
def make_sound(self):
print "Meow! Meow!"