Question

In: Computer Science

hi i do not know what is wrong with my python code. this is the class:...

hi i do not know what is wrong with my python code.

this is the class:

class Cuboid:
    def __init__(self, width, length, height, colour):
        self.__width = width
        self.__length = length
        self.__height = height
        self.__colour = colour
        self.surface_area = (2 * (width * length) + 2 * (width * height) + 2 * (length * height))
        self.volume = height * length * width

    def get_width(self):
        return self.__width

    def get_length(self):
        return self.__length

    def get_height(self):
        return self.__height

    def get_colour(self):
        return self.__colour

    def set_width(self, width):
        if isinstance(width, (int, float)):
            self.__width = width

    def set_length(self, length):
        if isinstance(length, (int, float)):
            self.__length = length

    def set_height(self, height):
        if isinstance(height, (int, float)):
            self.__height = height

    def set_colour(self, colour):
        if colour:
            if colour(" ", "").isalnum():
                self.__colour = colour

    def get_surface_area(self, surface_area):

        return self.surface_area

    def get_volume(self, volume):
        return self.volume

    def __str__(self):
        desc = f"The {self.__colour} Cuboid Measurments: \n" \
               f"(Width = {self.__width}, Length = {self.__length}, Height = {self.__height})" \
               f"Surface Area = {self.surface_area}" \
               f"Volume = {self.volume}"
        return desc

this is the demo code:

from cuboid import Cuboid
def main():
    cuboid1 = Cuboid("Blue", 10, 13, 54)
    cuboid2 = Cuboid("Red", 11, 63, 78)

    print(cuboid1)
    print(cuboid2)

main()

Solutions

Expert Solution

Hi I have resolved the errors.. The code is right but the method signatures were wrong... Like for init you didn't put double underscore.. And a small small syntax errors are there.. Also you have declared the init method with width, length, height, color but in mai you are passing color, height, length, width like that the arguments should be in the same order. Find the below code..

class Cuboid:
def __init__(self, width, length, height, colour):
self.__width = width
self.__length = length
self.__height = height
self.__colour = colour
self.surface_area = (2 * (width * length) + 2 * (width * height) + 2 * (length * height))
self.volume = height * length * width

def get_width(self):
return self.__width

def get_length(self):
return self.__length

def get_height(self):
return self.__height

def get_colour(self):
return self.__colour

def set_width(self, width):
if isinstance(width, (int, float)):
self.__width = width

def set_length(self, length):
if isinstance(length, (int, float)):
self.__length = length

def set_height(self, height):
if isinstance(height, (int, float)):
self.__height = height

def set_colour(self, colour):
if colour:
if colour(" ", "").isalnum():
self.__colour = colour

def get_surface_area(self, surface_area):

return self.surface_area

def get_volume(self, volume):
return self.volume

def _str_(self):
desc=""
desc = desc+"The "+str(self.__colour)+" Cuboid Measurments:" +"Width = "+str(self.__width) +", Length = "+str(self.__length)+", Height = "+str(self.__height) +" , Surface Area = "+str(self.surface_area) +" , Volume = "+str(self.volume)
return desc


def main():
cuboid1 = Cuboid(10,13,54,"Blue")
cuboid2 = Cuboid(11,63,78,"Red")
print(cuboid1.get_colour())
print(cuboid2.get_colour())
print(cuboid1.get_volume(900))
print(cuboid2.get_surface_area(89))
print(cuboid1._str_())
main()

Output :


Related Solutions

I have an unexpected indent with my python code. please find out whats wrong with my...
I have an unexpected indent with my python code. please find out whats wrong with my code and run it to show that it works here is the code : def main(): lis = inputData() customerType = convertAcct2String(lis[0]) bushCost = getBushCost(lis[0],int(lis[1],10)) flowerCost = getFlowerBedCost(int(lis[2],10),int(lis[3],10)) fertiCost = getFertilCost(int(lis[4],10)) totalCost = calculateBill(bushCost,fertiCost,flowerCost) printReciept(customerType,totalCost,bushCost,fertiCost,flowerCost) def inputData(): account, number_of_bushes,flower_bed_length,flower_bed_width,lawn_square_footage = input("Please enter values").split() return [account, number_of_bushes,flower_bed_length,flower_bed_width,lawn_square_footage] def convertAcct2String(accountType): if accountType== "P": return "Preferred" elif accountType == "R": return "Regular" elif accountType == "N": return...
HI can I please know whats wrong in this 2to1 mux code in VHDL code also...
HI can I please know whats wrong in this 2to1 mux code in VHDL code also please type it out so theres no confusion thank you -- Code your design here library IEEE; use IEEE.std_logic_1164.all; -- entity declaration for testbench entity test mux2 is end test; --architecture Body declaration for 2to1 mux -- component declaration of source entity 2to1 mux component test mux2 is port ( sel : in std_logic ; --select input, A : in std_logic ; --data input...
Python I want to name my hero and my alien in my code how do I...
Python I want to name my hero and my alien in my code how do I do that: Keep in mind I don't want to change my code except to give the hero and alien a name import random class Hero:     def __init__(self,ammo,health):         self.ammo=ammo         self.health=health     def blast(self):         print("The Hero blasts an Alien!")         if self.ammo>0:             self.ammo-=1             return True         else:             print("Oh no! Hero is out of ammo.")             return False     def...
This is my code for python. I am trying to do the fourth command in the...
This is my code for python. I am trying to do the fourth command in the menu which is to add an employee to directory with a new phone number. but I keep getting error saying , "TypeError: unsupported operand type(s) for +: 'dict' and 'dict". Below is my code. What am I doing wrong? from Lab_6.Employee import * def file_to_directory(File): myDirectory={}       with open(File,'r') as f: data=f.read().split('\n')    x=(len(data)) myDirectory = {} for line in range(0,199):      ...
I do not know why I keep getting this question wrong, I triple checked my work!...
I do not know why I keep getting this question wrong, I triple checked my work! A distribution of values is normal with a mean of 80 and a standard deviation of 18. From this distribution, you are drawing samples of size 23. Find the interval containing the middle-most 40% of sample means: ANSWER HERE Enter your answer using interval notation. In this context, either inclusive or exclusive intervals would be acceptable. Your numbers should be accurate to 1 decimal...
Can you please see what I have done wrong with my program code and explain, This...
Can you please see what I have done wrong with my program code and explain, This python program is a guess my number program. I can not figure out what I have done wrong. When you enter a letter into the program, its supposed to say "Numbers Only" as a response. I can not seem to figure it out.. instead of an error message. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if...
I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
Working with Python. I am trying to make my code go through each subject in my...
Working with Python. I am trying to make my code go through each subject in my sample size and request something about it. For example, I have my code request from the user to input a sample size N. If I said sample size was 5 for example, I want the code to ask the user the following: "Enter age of subject 1" "Enter age of subject 2" "Enter age of subject 3" "Enter age of subject 4" "Enter age...
My Javascript code isn't working (when i press calculate button) - what's wrong with it ?...
My Javascript code isn't working (when i press calculate button) - what's wrong with it ? Car Rental Enter Number of Rental Days: Select Car Type: onclick= "priceofcar = 50;"/> Compact onclick= "priceofcar = 60;"/> Economy onclick= "priceofcar = 70;"/> Intermediate Select Loss Damage Waiver onclick= "damagewaiver='yes'"/> Yes onclick= "damagewaiver='no'"/> No damagewaiver = boxDays.value * 25;} else if (damagewaiver == No) { damagewaiver = 0; }/> Select Roadside Issues Coverage: onclick= "issuescoverage='yes'"/> Yes onclick= "issuescoverage='no'"/> No issuescoverage = boxDays.value *...
HI. I have been trying to run my code but I keep getting the following error....
HI. I have been trying to run my code but I keep getting the following error. I can't figure out what I'm doing wrong. I also tried to use else if to run the area of the other shapes but it gave me an error and I created the private method. Exception in thread "main" java.util.InputMismatchException at java.base/java.util.Scanner.throwFor(Scanner.java:939) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at project2.areacalculation.main(areacalculation.java:26) My code is below package project2; import java.util.Scanner; public class areacalculation { private static...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT