petriajack8375
02.06.2021 •
Computers and Technology
Complete the following function, strcat_ba(a, b), so that given two strings, a and b, it returns the concatenation of b followed by a (pay attention to the order in these instructions!). In [18]: def strcat_ba(a, b): assert type(a) is str, f"Input argument "a" has "type(a) is {type(a) } rather than str' " return (a+b) assert type(b) is str, f"Input argument b' has "type(b) is {type(b) } rather than 'str' " In [8]: # strcat_ba_test : Test cell # Workaround: # Python 3.5.2 does not have random. choices() (available in 3.6+) def random_letter( ) : from random import choice return choice( '' ) def random_string(n, fun=random_letter) : return '' . join( [str (fun() ) for _ in range(n) ]) = random_string(5) b = random_string(3) c = strcat_ba(a, b) print( 'streat_ba("{}", "{}") == "{}" . format(a, b, c)) assert len(c) == len(a) + len(b), " c' has the wrong length: {len(c)} rather than {len(a)+len(b)}" assert c[ : len(b) ] == b assert c [-len(a) : ] == a print ("\n(Passed!)") streat_ba( "fazcw", "cpe") == "fazcwcpe" AssertionError Traceback (most recent call last) <ipython-input-8-6618c8ad9c30> in <module> 14 print( 'streat_ba("{}", "{}") = = "{}"'. format(a, b, c)) 15 assert len(c) == len(a) + len(b), " c" has the wrong length: {len(c)} rather than {len(a)+len(b)}" ---> 16 assert c[ : len(b) ] == b 17 assert c[- len(a) : ] == a 18 print("\n(Passed! )") AssertionError :
Solved
Show answers
More tips
- S Sport How to Learn to Pull Up on Monkey Bars?...
- L Leisure and Entertainment Scrapbooking: What is it and Why is it Becoming More Popular?...
- H Horoscopes, Magic, Divination How to Cast a Love Spell on a Guy? Guide for Guys...
- F Family and Home How to Sew Curtain Tapes: Best Tips from Professionals...
- S Style and Beauty How are artificial nails removed?...
- S Style and Beauty How to Make Your Lips Fuller? Ideas and Tips for Beautiful Lips...
- F Food and Cooking The Disease That Haunted Abraham Lincoln...
- C Computers and Internet How to Get Rid of Windows Genuine Check?...
- H Health and Medicine How to perform artificial respiration?...
- S Style and Beauty Tricks and Tips: How to Get Rid of Freckles...
Answers on questions: Computers and Technology
- C Computers and Technology School officials want to show the percentage of students who buy lunch from the school cafeteria compared to the percentage of those who bring their lunch. which type...
- E English How is being respectful you have more friends...
- M Mathematics Asquare piece of fabric has an area of 595 cm2. to the nearest tenth, what is the length of 1 side of the fabric? a. 21.3 cm b. 23.2 cm c. 24.4 cm d. 25.6 cm...
- B Biology If shoe it to foot , as glove is to the following: simple sugar (monosaccharide) is to carbohydrate as amino acid it...
- E English Henry huggins chapter 5 what happens on the way to the dog show? a. ribsy gets tangled in his leash. b. ribsy rolls in the dirt. c. ribsy lies down in a puddle. d....
- H Health Which pair of variables has a clear causal link? a.sales of hot dogs and cold coffee at a snack bar b.the number of road accidents and the number of vegetarians in...
- E English All of the following are disadvantages of an extemporaneous speech, except: a. requires extensive practice b. difficult to deliver without presentation aids c. gives...
- E English What is the main subject of the passage...
- H History Why did mexican immigration to the united states increase during and after the mexican revolution...
- C Chemistry If element x has 95 protons how many electrons does it have...
Ответ: