using python 3:
Do not change the tests. Write the body of the distFromOrigin method.
class Point:
def __init__(self, initX, initY):
""" Create a new point at the given coordinates """
self.__x = initX
self.__y = initY
def getX(self):
""" Get its x coordinate """
return self.__x
def getY(self):
""" Get its y coordinate """
return self.__y
def __str__(self):
""" Return a string representation of self """
return "({}, {})".format(self.__x, self.__y)
def distFromOrigin(self):
""" Return the distance between self and (0,0) """
return 0
if __name__ == "__main__":
import test
a = Point(-4,3)
test.testEqual(a.distFromOrigin(), 5)
b = Point(1,1)
test.testEqual(b.distFromOrigin(), 2**0.5)
class Point:
def __init__(self, initX, initY):
""" Create a new point at the given coordinates """
self.__x = initX
self.__y = initY
def getX(self):
""" Get its x coordinate """
return self.__x
def getY(self):
""" Get its y coordinate """
return self.__y
def __str__(self):
""" Return a string representation of self """
return "({}, {})".format(self.__x, self.__y)
def distFromOrigin(self):
""" Return the distance between self and (0,0) """
return ((self.__x*self.__x)+(self.__y*self.__y))**(0.5)
if __name__ == "__main__":
import test
a = Point(-4,3)
test.testEqual(a.distFromOrigin(), 5)
b = Point(1,1)
test.testEqual(b.distFromOrigin(), 2**0.5)
using python 3: Do not change the tests. Write the body of the distFromOrigin method. class...
import math ''' Finish the code below as described. Use the completed class Square as an example. ''' class Square: ''' Each Square has a width and can calculate its area, its perimeter, and return a string representation of itself. ''' def __init__(self, width): ''' (float) -> None Create a new Square with the given width. ''' self.width = width def get_area(self): ''' () -> float Return this square's area. ''' return self.width*self.width def get_perimeter(self): ''' () -> float Return...
Need Help! in English Can not get program to run plz include detailed steps as comments of what i did not do what I have done so far class Point: def __init__(self): self._x = 0 self._y = 0 def getX(self): return self._x def setX(self, val): self._x = val def getY(self): return self._y def setY(self, val): self._y = val def __init__(self, initX = 0, initY = 0): self._x = initX self._y = initY def __str__(self): return '<'+str(self._x)+', '+str(self._y)+ '>' def scale(self, factor):...
Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born which is a subclass of Famous_Person. Add a method to calculate the day of the week the person was born and print out all of the corresponding information using the overridden print method. Use the following code below as a starting point. ////////////////////////////////////////////////////// from datetime import datetime class Famous_Person(object): def __init__(self, last, first, month,day, year): self.last = last self.first = first self.month = month...
Write a program that does the following in Python Code: Write a new Class called Famous_Day_Born which is a subclass of Famous_Person. Add a method to calculate the day of the week the person was born and print out all of the corresponding information using the overridden print method. Use the following code below as a starting point. ////////////////////////////////////////////////////// from datetime import datetime class Famous_Person(object): def __init__(self, last, first, month,day, year): self.last = last self.first = first self.month = month...
Please code in Python Revise the AbstractBag class so that it behaves as a subclass of AbstractCollection provided in the file abstractcollection.py. Abstractcollection.py code: class AbstractCollection(object): """An abstract collection implementation.""" # Constructor def __init__(self, sourceCollection = None): """Sets the initial state of self, which includes the contents of sourceCollection, if it's present.""" self.size = 0 if sourceCollection: for item in sourceCollection: self.add(item) # Accessor methods def isEmpty(self): """Returns True if len(self) == 0, or False otherwise.""" return len(self) == 0...
ill thumb up do your best
python3
import random
class CardDeck:
class Card:
def __init__(self, value):
self.value = value
self.next = None
def __repr__(self):
return "{}".format(self.value)
def __init__(self):
self.top = None
def shuffle(self):
card_list = 4 * [x for x in range(2, 12)] + 12 * [10]
random.shuffle(card_list)
self.top = None
for card in card_list:
new_card = self.Card(card)
new_card.next = self.top
self.top = new_card
def __repr__(self):
curr = self.top
out = ""
card_list = []
while curr is not None:...
Hi I'm trying to write a code for a web server in python with flask. This is what I have so far from flask import Flask app = Flask(__name__) @app.route('/') #first endpoint i.e. "http://localhost/" def index(): return 'hello' #return data in string if __name__ == '__main__': app.run(debug=True) After running the code, I'm given a address to the web with the text hello. The problem is that this only works with my computer that is running the code. If I try...
How do you do this? class Event: """A new calendar event.""" def __init__(self, start_time: int, end_time: int, event_name: str) -> None: """Initialize a new event that starts at start_time, ends at end_time, and is named name. Precondition: 0 <= start_time < end_time <= 23 >>> e = Event(12, 13, 'Lunch') >>> e.start_time 12 >>> e.end_time 13 >>> e.name 'Lunch' """ self.start_time = start_time self.end_time = end_time self.name = event_name def __str__(self) -> str: """Return a string representation of this...
%%%%Python Question%%% Work from the template acrostic.py, which you can find on the ELMS page for this assignment. • In the Generator class, write an __init__() method with two parameters: self and the path to a text file containing one word per line. This method should read the words from the file, strip off leading and trailing whitespace, and store them in a dictionary where each key is a lower-case letter and each corresponding value is a list of words...
Please write a code in python! Define and test a function named posterize. This function expects an image and a tuple of RGB values as arguments. The function modifies the image like the blackAndWhite function, but it uses the given RGB values instead of black. images.py import tkinter import os, os.path tk = tkinter _root = None class ImageView(tk.Canvas): def __init__(self, image, title = "New Image", autoflush=False): master = tk.Toplevel(_root) master.protocol("WM_DELETE_WINDOW", self.close) tk.Canvas.__init__(self, master, width = image.getWidth(), height = image.getHeight())...