Question

I am currently facing a problem with my python program which i have pasted below where i have to design and implement python classes and record zoo database and takes user input as query. the error i...

I am currently facing a problem with my python program which i have pasted below where i have to design and implement python classes and record zoo database and takes user input as query. the error i am recieving says that in line 61 list index is out of range. kindly someone help me with it as soon as possible. Below is the program kindly check and correct it. Thanks!

class Animal:
def __init__(self, name, types, species, mass):
self.name=name
self.type=types
self.specie=species
self.mass=mass

def getName(self):
return self.name

def getType(self):
return self.type

def getSpecies(self):
return self.specie

def getMass(self):
return self.mass

class Mammal(Animal):
def __init__(self,name, types, species, mass, litterSize):
super().__init__(self, name, types, species, mass)
self.litterSize=litterSize

def getLitterSize(self):
return self.litterSize

class Reptiles(Animal):
def __init__(self, name, types, species, mass, VenemOrNot):
super().__init__(self, name, types, species, mass)
self.VenomOrNot=VenomOrNot

def getVenomOrNot(self):
return self.VenomOrNot

class Birds(Animal):
def __init__(self, name, types, species, mass, Wingspan, TalksOrMute, phrase):
super().__init__(self, name, types, species, mass)
self.Wingspan=Wingspan
self.TalksOrMute=TalksOrMute
self.phrase=phrase

def getWingspan(self):
return self.Wingspan

def TalksOrMute(self):
return self.TalksOrMute

def getPhrase(self):
return self.phrase


if __name__=='__main__':
file_read=open('Animals.txt', 'r')

animalsList=[]
for line in file_read:
details=line.split()

if details[1]=="Mammal":
m=Mammal(details[0], details[1], details[2], details[3], details[4])
animalsList.appened(m)

elif details[1]=="Reptile":
r=Reptile(details[0], details[1], details[2], details[3], details[4])
animalsList.append(r)

elif details[1]=="Bird":
phrase=""
if details[5]=="Talks":
phrase=file_read.readline().rstrip('\n')
b=Birds(details[0], details[1], details[2], details[3], details[4], details[5], phrase)
animalsList.append(b)

while True:
choice=input('Query animal species[s], mass[m], litter[l], venom[v], wingspan[w], talk[t] or exit session[e]?')
if choice=='s':
name=input('Animal Name?')
for animal in animalsList:
if name==animal.getName():
print(name, 'species is', animal.getSpecies())
break
else:
print(name, 'not present')

elif choice=='m':
name=input('Animal Name?')
for animal in animalsList:
if name==animal.getName():
print(name,'mass is', animal.getMass())
break
else:
print(name, 'not present')

elif choice=='l':
name=input('Animal Name?')
for animal in animalsList:
if name==animal.getName() and animal.getType=="Mammal":
print(name, 'litter Size is', animal.getLitterSize())
break
else:
print(name, 'not present')

elif choice=='v':
name=input('Animal Name?')
for animal in animalsList:
if name==animal.getName() and animal.getType=='Reptile':
print(name, 'is', animal.getVenomOrNot())
break
else:
print(name, 'not present')

elif choice=='w':
name=input('Animal Name?')
for animal in animalsList:
if name==animal.getName() and animal.getType=='Birds':
if animal.getTalksOrMute()=="Mute":
print(name,'Is Mute')
else:
print(name, 'talks')
print(name, 'says', animal.getPhrase())
break
else:
print(name, 'not present')

elif choice=='e':
print('Goodbye!')
break
else:
print('Invalid choice entered')

Below is the information which exists in my. txt file:

Bob Mammal Bear 300
2
Lucy Reptile Lizard 2
Nonvenomous
Carl Reptile Cottonmouth 3
Venomous
Oliver Bird Ostrich 75
60 Mute
Polly Bird Parrot 1
2 Talks
I want a cracker
Doug Mammal Dog 20
4

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment....

1 class Animal: def __init_(self, name, types, species, mass): self.name-name 3 self.type-types 4 self.specie-species self.ma23 class Reptile(Animal): def _init_(self, name, types, species, mass, VenomOrNot): 24 super)._init_(name, types, species, maif_name_=-main-: 43 file_read-open Animals.txt, r animal s List=[] 45 for line in file_read: 46 details-line.split) 47

while True: 60 choice-input( Query animal species[s], mass[m], litterll], venom[v], 61 wingspan[w], talk[t] or exit session[elif choice=l: name-input( Animal Name?) 79 80 for animal in animalsList: if name-animal.getName() and animal.getType-Ma100 else: print (name, talks) 101 print (name, says, animal.getPhrase()) 102 break 103 104 else: print(name, not present

Animals.txt

Bob Mammal Bear 300 2
Lucy Reptile Lizard 2 Nonvenomous
Carl Reptile Cottonmouth 3 Venomous
Oliver Bird Ostrich 75 60 Mute
Polly Bird Parrot 1 2 Talks
I want a cracker
Doug Mammal Dog 20 4

Code:

class Animal:

def __init__(self, name, types, species, mass):

self.name=name

self.type=types

self.specie=species

self.mass=mass

def getName(self):

return self.name

def getType(self):

return self.type

def getSpecies(self):

return self.specie

def getMass(self):

return self.mass

class Mammal(Animal):

def __init__(self,name, types, species, mass, litterSize):

super().__init__(name, types, species, mass)

self.litterSize=litterSize

def getLitterSize(self):

return self.litterSize

class Reptile(Animal):

def __init__(self, name, types, species, mass, VenomOrNot):

super().__init__(name, types, species, mass)

self.VenomOrNot=VenomOrNot

def getVenomOrNot(self):

return self.VenomOrNot

class Birds(Animal):

def __init__(self, name, types, species, mass, Wingspan, TalksOrMute, phrase):

super().__init__(name, types, species, mass)

self.Wingspan=Wingspan

self.TalksOrMute=TalksOrMute

self.phrase=phrase

def getWingspan(self):

return self.Wingspan

def TalksOrMute(self):

return self.TalksOrMute

def getPhrase(self):

return self.phrase

if __name__=='__main__':

file_read=open('Animals.txt', 'r')

animalsList=[]

for line in file_read:

details=line.split()

if details[1]=="Mammal":

m=Mammal(details[0], details[1], details[2], details[3], details[4])

animalsList.append(m)

elif details[1]=="Reptile":

r=Reptile(details[0], details[1], details[2], details[3], details[4])

animalsList.append(r)

elif details[1]=="Bird":

phrase=""

if details[5]=="Talks":

phrase=file_read.readline().rstrip('\n')

b=Birds(details[0], details[1], details[2], details[3], details[4], details[5], phrase)

animalsList.append(b)

while True:

choice=input('Query animal species[s], mass[m], litter[l], venom[v], wingspan[w], talk[t] or exit session[e]?')

if choice=='s':

name=input('Animal Name?')

for animal in animalsList:

if name==animal.getName():

print(name, 'species is', animal.getSpecies())

break

else:

print(name, 'not present')

elif choice=='m':

name=input('Animal Name?')

for animal in animalsList:

if name==animal.getName():

print(name,'mass is', animal.getMass())

break

else:

print(name, 'not present')

elif choice=='l':

name=input('Animal Name?')

for animal in animalsList:

if name==animal.getName() and animal.getType=="Mammal":

print(name, 'litter Size is', animal.getLitterSize())

break

else:

print(name, 'not present')

elif choice=='v':

name=input('Animal Name?')

for animal in animalsList:

if name==animal.getName() and animal.getType=='Reptile':

print(name, 'is', animal.getVenomOrNot())

break

else:

print(name, 'not present')

elif choice=='w':

name=input('Animal Name?')

for animal in animalsList:

if name==animal.getName() and animal.getType=='Birds':

if animal.getTalksOrMute()=="Mute":

print(name,'Is Mute')

else:

print(name, 'talks')

print(name, 'says', animal.getPhrase())

break

else:

print(name, 'not present')

elif choice=='e':

print('Goodbye!')

break

else:

print('Invalid choice entered')

Add a comment
Know the answer?
Add Answer to:
I am currently facing a problem with my python program which i have pasted below where i have to design and implement python classes and record zoo database and takes user input as query. the error i...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am currently facing a problem with my python program which i have pasted below where...

    I am currently facing a problem with my python program which i have pasted below where i have to design and implement python classes and record zoo database and takes user input as query. the error i am recieving says that in line 61 list index is out of range. kindly someone help me with it as soon as possible. Below is the program kindly check and correct it. Thanks! class Animal: def __init__(self, name, types, species, mass): self.name=name self.type=types...

  • I am having trouble with my Python code in this dictionary and pickle program. Here is...

    I am having trouble with my Python code in this dictionary and pickle program. Here is my code but it is not running as i am receiving synthax error on the second line. class Student: def__init__(self,id,name,midterm,final): self.id=id self.name=name self.midterm=midterm self.final=final def calculate_grade(self): self.avg=(self.midterm+self.final)/2 if self.avg>=60 and self.avg<=80: self.g='A' elif self.avg>80 and self.avg<=100: self.g='A+' elif self.avg<60 and self.avg>=40: self.g='B' else: self.g='C' def getdata(self): return self.id,self.name.self.midterm,self.final,self.g CIT101 = {} CIT101["123"] = Student("123", "smith, john", 78, 86) CIT101["124"] = Student("124", "tom, alter", 50,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT