Question

10q

For the following question, refer to the Python module on the right, as well as the name of the file that contains each modulFor the following question, refer to the Python module on the right, as well as the name of the file that contains each modul

I need help this is a python language

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

1)

OUTPUT

(base) C:\Users\SAW\Downloads>python main.py Garfield, Meow! Odie, woof! woof! Nicholas P Wilde, Jacha-chacha-chacha-chow! Ju

CODE

animals.py

#class Animal
class Animal:
        #constructor
        def __init__(self, name):
                #initializing name
                self.name = name
                
        #getName
        def getName(self):
                #returns name
                return self.name
                
        #speak
        def speak(self):
                #returns "Animals can't speak."
                return "Animals can't speak."
        
#class Cat derived from Animal
class Cat(Animal):
        #speak
        def speak(self):
                #returns 'Meow!'
                return 'Meow!'

#class Dog derived from Animal          
class Dog(Animal):
        #speak
        def speak(self):
                #returns 'woof! woof!'
                return 'woof! woof!'
        
#class Fox derived from Animal
class Fox(Animal):
        #speak
        def speak(self):
                #returns 'Jacha-chacha-chacha-chow!'
                return 'Jacha-chacha-chacha-chow!'
                

main.py

#importing animals.py
import animals

#list of objects for classes in animals.py
alist = [animals.Cat('Garfield'), 
                 animals.Dog('Odie'), 
                 animals.Fox('Nicholas P Wilde'), 
                 animals.Animal('Judy Hopps')]

#for loop
for a in alist:
        #calling getName and speak for each object
        print(a.getName() + ', ' + a.speak())
        

CODE SCREEN SHOT

main.py animals.py X #class Animal class Animal: #constructor def init (self, name) : #initializing name self.name = name HTT

main.py X | animals.py X 1 #importing animals.py 2 import animals 3 4 #list of objects for classes in animals.py 5 Falist = [

2)

CODE

vehicle.py

#class Vehicle
class Vehicle:
        #constructor
        def __init__(self, max_speed):
                #initializing max
                self.max = max_speed
                
        #getMaxSpeed
        def getMaxSpeed(self):
                #returns max
                return self.max
                

car.py

#importing vehicle.py
import vehicle

#class Car derived from Vehicle
class Car(vehicle.Vehicle):
        #constructor
        def __init__(self):
                #initializing max_speed
                max_speed = 120
                
                #passing value to class Vehicle
                super(Car, self).__init__(max_speed)
                

truck.py

#importing vehicle.py
import vehicle

#class Truck derived from Vehicle
class Truck(vehicle.Vehicle):
        #constructor
        def __init__(self):
                #initializing max_speed
                max_speed = 90
                
                #passing value to class Vehicle
                super(Truck, self).__init__(max_speed)
                

main

#importing vehicle.py, car.py, truck.py
import vehicle, car, truck

#object of class Vehicle
bullet_train = vehicle.Vehicle(300)

#calling getMaxSpeed
bullet_train.getMaxSpeed()

#object of class Car
c = car.Car()

#calling getMaxSpeed
c.getMaxSpeed()

#object of class Truck
t = truck.Truck()

#calling getMaxSpeed
t.getMaxSpeed()

OUTPUT

import vehicle, car, truck bullet_train = vehicle.Vehicle (300) bullet_train.getMaxSpeed() 300 >>> c = car.Car() >>> c.getMax

CODE SCREEN SHOT

vehicle.py

1 2 3 4 5 6 7 8 9 10 11 #class Vehicle class Vehicle: #constructor def init__(self, max_speed): #initializing max self.max =

car.py

#importing vehicle.py import vehicle 1 2 3 4 5 6 7 8 #class Car derived from Vehicle class Car (vehicle. Vehicle): #construct

truck.py

#importing vehicle.py import vehicle 1 2 3 4 5 6 7 8 9 10 11 12 #class Truck derived from Vehicle class Truck (vehicle. Vehic

main.py

1 #importing vehicle.py, car.py, truck.py import vehicle, car, truck 2 3 4 5 6 #object of class Vehicle bullet_train = vehicl

Add a comment
Know the answer?
Add Answer to:
10q I need help this is a python language For the following question, refer to the...
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
  • 11q Language is python need help 1) What is the output of the following code? Refer...

    11q Language is python need help 1) What is the output of the following code? Refer to the class defined here. Example: File 1: asset.py import asset class Asset: brains = asset.Asset( "Brains" ) strength = asset. Asset( "Strength" ) steel = asset.Asset( "Steel" ) wheelbarrow = asset. Asset( "Wheelbarrow" ) cloak = asset.Asset( "Cloak" ) def _init__( self, name): self.mName = name return def getName( self ): return self.mName al = strength + steel a2 = cloak + wheelbarrow...

  • HELP ASAP !! I WILL RATE !!!! QUESTION 8 Consider the following class definitions: class Animal:...

    HELP ASAP !! I WILL RATE !!!! QUESTION 8 Consider the following class definitions: class Animal: def _init__(self, name, habitat): if habitat != self.habitat: raise Exception('{0:10s} is an invalid habitat for animal {1:12s} ! format (habitat, name)) self.name = name class Horse (Animal): habitat = 'land' def moves (self): print("\nThe horse named {0:10s) gallops on (1:8s}'. format self.name, self.habitat)) class Whale(Animal): habitat = 'ocean def moves (self): print ('\nThe whale named {0:10s} swims along ) format(self.name)) class Tiger(Animal): habitat =...

  • 9c Python 1) What is the output of the following code? Refer to the Weapon, Blaster,...

    9c Python 1) What is the output of the following code? Refer to the Weapon, Blaster, and Bowcaster classes. File 1: weapon.py class Weapon: def init ( self, power ): self.mPower = power return Example: import blaster from bowcaster import Bowcaster def getPower( self ): return self.mPower han = blaster.Blaster( 8000, 20 ) print("HP:", han.getPower( ) ) print( "HR:", han.getFireRate()) chewie = Bowcaster( 3000, 6) print( "CB:", chewie.getBarrelSize()) print( "CR:", chewie.getRange()) File 2: blaster.py import weapon class Blaster( weapon. Weapon):...

  • 10p Python For the following question, refer to the Python module on the right, as well...

    10p Python For the following question, refer to the Python module on the right, as well as the code below. 1) What is the output of the following code? #dodgeable.py #main dodgeable.py import dodgeable class Locatable: def NUM_CARS = 3 init (self,x,y): NUM TRUCKS = 2 self.mX = X WIDTH = 60 self.mY = y def setx (self,x): def main (): self.mX = x object_list = [] def sety (self, y): self.mY = y for i in range (NUM_CARS) :...

  • 9p This is for Python I need help. Pet #pet.py mName mAge class Pet: + __init__(name,...

    9p This is for Python I need help. Pet #pet.py mName mAge class Pet: + __init__(name, age) + getName + getAge0 def init (self, name, age): self.mName = name self.mAge = age Dog Cat def getName(self): return self.mName mSize mColor + __init__(name, age,size) + getSize() + momCommento + getDog Years() +_init__(name, age,color) + getColor + pretty Factor + getCatYears def getAge(self): return self.mAge #dog.py import pet #cat.py import pet class Dog (pet. Pet): class Cat (pet. Pet): def init (self,...

  • 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...

  • 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...

  • PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please...

    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,...

  • PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment...

    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...

  • 11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl...

    11p Python Language Read the following code for oofraction. import oofraction class OOFraction: def main(): fl = oofraction.o0Fraction( 2, 5) f2 = oofraction.o0Fraction ( 1, 3) f3 = f1 + f2 print (str(3)) main() def __init__(self, Num, Den): self.mNum = Num self.mDen = Den return def_add_(self,other): num = self.mNumother.mDen + other.mNum*self.mDen den = self.mDen*other.mDen f = OOFraction(num,den) return f 1. Write the output below. def_str_(self): s = str( self.mNum )+"/" + str( self.mDen) returns 2. Write a class called wholeNum...

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