Question

Page 3 of 7 (Python) For each substring in the input string t that matches the regular expression r, the method call re. aub
Eile: A.pY A: A object def init (selt, the x) A(2) self.x the x+3 def str (selt): returna otr(self.x) a # Source code file:
Page 3 of 7 (Python) For each substring in the input string t that matches the regular expression r, the method call re. aub (r, o, t) substitutes the matching substring with the string a. Wwhat is the output? import re print (re.aub (r"l+\d+ " , "$, "be+345jk3726-45+9xyz")) a. "be$jk3726-455xyz" c. "bejkxyz" 9. b. "be$jks-$$xyz" d. $$$" A object a- A (2) 10. (Python) What is the output? # Source code file: A.py class A init (self, the x): self.x- the_x+3 def str (self) return "a" atr(self.x) +a" def B object t = B (2, 6) # Source code file: B.py elass B(A): y init (self, the x, the y) (the x + 4) def super).init self.y the y 2 _repr (self) : return "b" str (self.y+ self.x) "b def # Source code: test.py S A(2) t B (2, 6) print (str (s) , str(t), repr (t)) a. a5a a5a b17b b. a5a a9a b21b c. a5a a5a b125b d. a5a a9a b129b 11. (Python) If the method last is defined like this, which of the assertEqual statements passes? def last (s): if len (s) return s[len (s) 1] > 0: else: return n
Eile: A.pY A: A object def init (selt, the x) A(2) self.x the x+3 def str (selt): returna otr(self.x) "a # Source code file: B.py class B(A) : def init (self, the x. the y) super) init (the x 4) self.y- the y 2 B object t B12, 6) Y def repr return "b (self) +selt.x) "b " +str(self.y # Source code: test.py -A(2) t B(2, 6) print (str(a), str(t), repr(t)) d. aSa a9a b129b C aSa a5a b125b b. aSa a9a b21b a. aSa a5a b17b 11. (Python) If the method last is defined like this, which of the assertEqual statements passes? def last (s): if len(s)> 0: 1) return s[len (s) else: return " s [i] returns the letter of indexi from the string. a. self.assert Equal (last ("cat", "c") b. self.assert Equal (last ("cat ", False) c. self.assertEqual (last ("dog", "g") d. self.assert Equal (last ("dog", True) Note:
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
Page 3 of 7 (Python) For each substring in the input string t that matches 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
  • [Problem 5] List all that the following Python class is missing in order to function. [10...

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

    ## 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__() :...

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

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

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

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

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

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

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

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