So the answer to Q11 is option C.
It is so because initially " if " condition would be executed as text length of the "dog" is greater than 0.
Therefore the value of s[2] would return which is "g".
Now since last(dog) is equal to g, self.assertEqual statement would pass
Page 3 of 7 (Python) For each substring in the input string t that matches the...
[Problem 5] List all that the following Python class is missing in order to function. [10 Points] import math class TwoCoordinatePoints (object): #This class represents a point A = (x, y) with integer values for x and y. -_init__(x, y): self.x = x self.y = y def -_str__(self): "(%, %)" % (self.x, self.y) def distance (self, P): #computes the distance between two points (instances) of this class return math.sqrt((self.x-P.x)**2+(self.y-P.y)**2)
Python UML .Can anyone helpe to understand the pthon UML, I appreicated it . Giving the python code as follows: class C(object): pass class D(object): pass class A(object): def _ _init_ _(self,x,y); self.x=x; self.y=y; def hello (self,str); prnt(str +str(c)) class B(A); def _ _init_ _(self); #this is "aggregation" not composition" self.c= C self.d= D if _ _name_ _ =="_ _main_ _"; a=A(10,20) # a=A(20,30) # (a)Draw an UML Class Diagram of A ,and an UML Class Diagram of B (b)Draw...
## python oop creating a large number of instances ## im trying to create a large number of instances for a class. could you show me a way to make it work import math import random class soldiers: def __init__(self,x,y): self.x = x self.y = y def get_target(self,x,y,number_red_soldiers,number_blue_soldiers): pass # self.target = def aiming_angle(self,x,y,target,enemy_x,enemy_y): dy = self.y-enemy_y[target] dx = self.x-enemy_x[target] angle =math.atan(dy/dx) a = 0 number_blue_soldiers= 10 number_red_soldiers = 10 for i in range(number_blue_soldiers): blue_x = random.randint(0,100,10) blue_y = random.randint(0,100,10)...
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...
Here is a Python program. import turtle class Box: def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height def show(self): turtle.up() turtle.goto(x, y) turtle.down() for _ in range(2): turtle.forward(width) turtle.right(90) turtle.forward(height) turtle.right(90) bigbox = Box(-100, -150, 200, 300) bigbox.show() turtle.done() If you run the above program, it will produce an error. What is the keyword that has...
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) :...
Can someone please help implement code for the following Python example! 44 This represents an entire grouping of Grade values as a list (named grades). as We can then dig through this list for interesting things and calculations by 46 calling the methods we're going to implement, 47 aB class G Define the GradeBook class, se def init (self): GradeBook constructor, create the only instance variable, S1 a list named grades, and initialize it to an empty list, This means...
PRBE Errors in Python Class and Test Filles. Correct the errors in source code in the O1ympicMeda traditional and unit rt c. Correct class and in the modules olympicmedal. code- do not recopy (5 Py, testi.py, and teat2.py. Mark your corrections directly on the source point penalty for recopying). Adding, deleting, or correcting a pair of parentheses braces ( { }), single quotes (·. double quotes (- .), or triple quotesぃ.. test scripts on pages 6 and 7. There are...
python function will Return True if string x contains 3 vowels in a row, in consecutive locations, false otherwise. assuming that 'vowels' refer to the following lowercase lttrs: a,e,i,o,u programs fails partially, only allowed to use float, str, int, appen, split, strip, len, range def vowels_three(x): for i in range (o, len(x), 2): if x[i] not in ('a,e,i,o,u'): return False return True
This CSIS 9 Python. Java Python Warmup-2 > string_times prev next | chance Given a string and a non-negative int n, return a larger string that is n copies of the original string. string_times('Hi', 2) – 'HiHi' string_times('Hi', 3) - 'HiHiHi' string_times('Hi', 1) – 'Hi' Solution: Go Save, Compile, Run (ctrl-enter) Show Solution def string_times (str, n): def string_times(str, n): result = "" for i in range(n): # range(n) is [0, 1, 2, .... n-1] result = result + str...