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
If you have any doubts, please give me comment....
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')
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 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,...
Python 3+ Adjust the following code so the two errors below are non-present: 1. __init__() : Since Pizza object don't have it's own set() datastructure, the toppings in the pizza object are manimupated from out of the object. (-1.0) 2. __eq__() : How about "self.toppings == other.toppings" rather than "self.toppings - other.toppin == set())". Code: ## Program 1 ## --------------------------------- class Pizza: def __init__(self, s='M', top=set()): self.setSize(s) self.toppings = top def setSize(self, s): self.size = s def getSize(self): return self.size...
Can you add code comments where required throughout this Python Program, Guess My Number Program, and describe this program as if you were presenting it to the class. What it does and everything step by step. import random def menu(): #function for getting the user input on what he wants to do print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the...
For my computer class I have to create a program that deals with making and searching tweets. I am done with the program but keep getting the error below when I try the first option in the shell. Can someone please explain this error and show me how to fix it in my code below? Thanks! twitter.py - C:/Users/Owner/AppData/Local/Programs/Python/Python38/twitter.py (3.8.3) File Edit Format Run Options Window Help import pickle as pk from Tweet import Tweet import os def show menu():...
PYTHON The provided code in the ATM program is incomplete. Complete the run method of the ATM class. The program should display a message that the police will be called after a user has had three successive failures. The program should also shut down the bank when this happens. [comment]: <> (The ATM program allows a user an indefinite number of attempts to log in. Fix the program so that it displays a message that the police will be called...
I have to write a program where the program prints a deck of cards. instead of having your regular suits and numbers the program will use a value for a number, id will be either rock, paper, or scissors, and the coin will be heads or tails. print example: 2 of rock heads. If the user is enters 1 the program will print out 30 of the print example and arrange them by there values. if the user enters 2...
PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...
PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList: def __init__(self): self.__head = None self.__tail = None self.__size = 0 def insert(self, i, data): if self.isEmpty(): self.__head = listNode(data) self.__tail = self.__head elif i <= 0: self.__head = listNode(data, self.__head) elif i >= self.__size: self.__tail.setNext(listNode(data)) self.__tail = self.__tail.getNext() else: current = self.__getIthNode(i - 1) current.setNext(listNode(data,...