<< Chapter < Page Chapter >> Page >
Figure 2 . Question 6.
def prod(a,b): return a*bdef sum(c,d): return c+dcomp = lambda w,x,y,z : sum(w,x) * prod(y,z) print(comp(3,4,5,6))=============================================================================== 210

Go to answer 6

Question 7

True or False? The code in the top panel of Figure 3 produces the output shown in the bottom panel of Figure 3 .

Figure 3 . Question 7.
highNumbers = list(filter((lambda x: x>5), range(10))) print(highNumbers)=============================================================================== [5, 6, 7, 8, 9]

Go to answer 7

Question 8

True or False? The code in the top panel of Figure 5 produces the output shown in the bottom panel of Figure 5 .

Figure 5 . Question 8.
import re str = "abcd$"if re.search(r'[ceg$]', str):print("Match") else:print("No Match") if re.search(r'[^abcd$]', str): print("Match")else: print("No Match")=============================================================================== MatchMatch

Go to answer 8

Question 9

True or False? The code in the top panel of Figure 7 produces the output shown in the bottom panel of Figure 7 .

Figure 7 . Question 9.
import re s = "pqrabcdefg-abcd-abc$"matches = re.findall(r'ab', s) for substr in matches:print(substr) searchObj = re.search(r'ab', s)if searchObj: print(str(searchObj.start()) + "-" + str(searchObj.end()))=============================================================================== abab ab3-5

Go to answer 9

Question 10

True or False? The code in the top panel of Figure 8 produces the output shown in the bottom panel of Figure 8 .

Figure 8 . Question 10.
myList = [0,1,2,3,4,5,6] print(myList)print("ok") print(*myList)=============================================================================== [0, 1, 2, 3, 4, 5, 6]ok [0, 1, 2, 3, 4, 5, 6]

Go to answer 10

Question 11

Note: You will need to understand lambda and filter to understand the code in most of the remaining questions.

True or False? The code in the top panel of Figure 10 produces the output shown in the bottom panel of Figure 10 .

Figure 10 . Question 11.
import re myList = ('Dick', 'TomDickHarry', 'Dick is my name')for testString in myList: print("Test string:",testString)lambdaFunction = lambda arg: re.search(r"Dick", arg) matchObject = lambdaFunction(testString)if(matchObject!=None): print(" Matching subString:",matchObject.group())=============================================================================== Test string: DickMatching subString: Dick Test string: TomDickHarryMatching subString: Dick Test string: Dick is my nameMatching subString: Dick

Go to answer 11

Question 12

True or False? The code in the top panel of Figure 11 produces the output shown in the bottom panel of Figure 11 .

Figure 11 . Question 12.
import re myList = ('Dick', 'TomDickHarry', 'Dick is my name')for testString in myList: print("Test string:",testString)lambdaFunction = lambda arg: re.match(r"Dick", arg) matchObject = lambdaFunction(testString)if(matchObject!=None): print(" Matching subString:",matchObject.group())=============================================================================== Test string: DickMatching subString: Dick Test string: TomDickHarryMatching subString: Dick Test string: Dick is my nameMatching subString: Dick

Questions & Answers

define biology infour way
Happiness Reply
What are types of cell
Nansoh Reply
how can I get this book
Gatyin Reply
what is lump
Chineye Reply
what is cell
Maluak Reply
what is biology
Maluak
what's cornea?
Majak Reply
what are cell
Achol
Explain the following terms . (1) Abiotic factors in an ecosystem
Nomai Reply
Abiotic factors are non living components of ecosystem.These include physical and chemical elements like temperature,light,water,soil,air quality and oxygen etc
Qasim
what is biology
daniel Reply
what is diffusion
Emmanuel Reply
passive process of transport of low-molecular weight material according to its concentration gradient
AI-Robot
what is production?
Catherine
Pathogens and diseases
how did the oxygen help a human being
Achol Reply
how did the nutrition help the plants
Achol Reply
Biology is a branch of Natural science which deals/About living Organism.
Ahmedin Reply
what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
cell is the smallest unit of the humanity biologically
Abraham
ok
Achol
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Itse 1359 introduction to scripting languages: python. OpenStax CNX. Jan 22, 2016 Download for free at https://legacy.cnx.org/content/col11713/1.32
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Itse 1359 introduction to scripting languages: python' conversation and receive update notifications?

Ask