import math
class shape(object):
"""Shape is an base class, which is largely intended to be abstract, that
is only used as a parent class to other classes which define specific shapes
and inherit the shape class' fuctions getArea() and printArea().
"""
def __init__(self):
'''constructor function for the shape class
'''
self.area = None
self.name = "shape"
def getArea(self):
'''returns the area of the shape, which is defined in the constructor
'''
return self.area
def printArea(self):
'''prints a statement identifying the shape by its name and giving the
area of the shape. Returns None.
'''
print "The area of this " + self.name + " is: " + str(self.area)
return None
< /code>
Ich kann keines der oben genannten ändern. Ich wurde beauftragt, auf dieser Klasse aufzubauen: < /p>
class rectangle(shape):
"""A new class 'rectangle' that will inherit functions from the class
'shape'.
"""
def __init__(self, width, height):
"""A constructor function for the class.
"""
self.name = "rectangle"
self.area = width * height
r = rectangle(2, 3)
r.printArea()
class triangle(shape):
"""A new class 'triangle' that will inherit functions from the class
'shape'.
"""
def __init__(self, width, height):
"""A constructor function for the class.
"""
self.name = "triangle"
self.area = (width * height) / 2.0
t = triangle(3, 4)
t.printArea()
< /code>
Jetzt muss ich die Bereiche des Rechtecks und Dreiecks außerhalb der Klassen zusammenfassen. Wie würde ich das machen? Mein Versuch ist drastisch falsch und ich weiß nicht wirklich, was ich damit mache: < /p>
def sumAreaOfShapes(shapeList):
"""The sum of all the areas of the shapes in the list.
"""
addition = str(t.getArea()) + str(r.getArea())
return addition
print sumAreaOfShapes([rectangle(1.5, 7), triangle(7, 12)])
< /code>
Alles, was tut, ist buchstäblich eine Nummer am Ende eines anderen zu kleben.def sumAreaOfShapes(shapeList):
"""The sum of all the areas of the shapes in the list.
"""
addition = (float(t.getArea()))+(float(c.getArea()))+(float(r.getArea()))
return addition
print sumAreaOfShapes([circle(100), rectangle(100, 100), triangle(100, 100)])
Ich bekomme jetzt eine Antwort, aber es ist ungefähr 90,00, daher summiert es tatsächlich die Werte aus der Klasse und nicht aus meinem Druck.
Ich habe Code, den ich gegeben habe: < /p> [code]import math
class shape(object): """Shape is an base class, which is largely intended to be abstract, that is only used as a parent class to other classes which define specific shapes and inherit the shape class' fuctions getArea() and printArea(). """
def __init__(self): '''constructor function for the shape class ''' self.area = None self.name = "shape"
def getArea(self): '''returns the area of the shape, which is defined in the constructor ''' return self.area
def printArea(self): '''prints a statement identifying the shape by its name and giving the area of the shape. Returns None. ''' print "The area of this " + self.name + " is: " + str(self.area) return None < /code> Ich kann keines der oben genannten ändern. Ich wurde beauftragt, auf dieser Klasse aufzubauen: < /p> class rectangle(shape): """A new class 'rectangle' that will inherit functions from the class 'shape'. """
def __init__(self, width, height): """A constructor function for the class. """ self.name = "rectangle" self.area = width * height
r = rectangle(2, 3)
r.printArea()
class triangle(shape): """A new class 'triangle' that will inherit functions from the class 'shape'. """
def __init__(self, width, height): """A constructor function for the class. """ self.name = "triangle" self.area = (width * height) / 2.0
t = triangle(3, 4)
t.printArea() < /code> Jetzt muss ich die Bereiche des Rechtecks und Dreiecks außerhalb der Klassen zusammenfassen. Wie würde ich das machen? Mein Versuch ist drastisch falsch und ich weiß nicht wirklich, was ich damit mache: < /p> def sumAreaOfShapes(shapeList): """The sum of all the areas of the shapes in the list. """ addition = str(t.getArea()) + str(r.getArea()) return addition
print sumAreaOfShapes([rectangle(1.5, 7), triangle(7, 12)]) < /code> Alles, was tut, ist buchstäblich eine Nummer am Ende eines anderen zu kleben.def sumAreaOfShapes(shapeList): """The sum of all the areas of the shapes in the list. """ addition = (float(t.getArea()))+(float(c.getArea()))+(float(r.getArea())) return addition
print sumAreaOfShapes([circle(100), rectangle(100, 100), triangle(100, 100)]) [/code] Ich bekomme jetzt eine Antwort, aber es ist ungefähr 90,00, daher summiert es tatsächlich die Werte aus der Klasse und nicht aus meinem Druck.
Ich habe ein 2-D-Array und es erfordert ein Cumsum-Reihen. Aber Axis wird in Numba nicht unterstützt. Also stecke ich fest. Jede Hilfe wird geschätzt.
from numba import jit
import numpy as np...
Aus meiner Lektüre dieser Antwort ist es möglich, ein Paar von zwei 4-Bit-Ganzzahlen mit nur einer Ergänzung und einigen bitweisen Operationen durchzuführen, und der Autor dieser Frage besagt, dass...
Ich habe einen allgemeinen Python-Code in Sage-Math geschrieben, um die Fourier-Transformation der Zugabe von zwei verschiedenen Frequenz-Cosinus-Wellen herauszufinden, um die Frequenzdomäne in einem...
Ich habe einen Xarray -Datensatz mit 3 Dimensionen (Zeit, Lon, Lat) und einer Wärmevariablen. Die Wärme nimmt die Werte 1 oder 0 (1 = mehr als 30DEGC, 0 = weniger als 30DEGC), und ich möchte die...
Ich habe einen Xarray -Datensatz mit 3 Dimensionen (Zeit, Lon, Lat) und einer Wärmevariablen. Die Wärme nimmt die Werte 1 oder 0 (1 = mehr als 30DEGC, 0 = weniger als 30DEGC), und ich möchte die...