<< Chapter < Page Chapter >> Page >
Figure 9 . Question 3 Python module named Py1359_1720r_03.py.
def sum(parA,parB): return parA + parBdef product(parC,parD): return parC * parD
Figure 10 . Question 3 test code named Py1359_1720r_03.txt.
>>>from Py1359_1720r_03 import sum>>>sum(2,3) 5>>>from Py1359_1720r_03 import product>>>product(2,3) 6
Figure 11 . Question 3 execution command.
python -m doctest -v Py1359_1720r_03.txt
Figure 12 . Question 3 possible output.
Trying: from Py1359_1720r_03 import sumExpecting nothing okTrying: sum(2,3)Expecting: 5ok Trying:from Py1359_1720r_03 import product Expecting nothingok Trying:product(2,3) Expecting:6 ok1 items passed all tests: 4 tests in Py1359_1720r_03.txt4 tests in 1 items. 4 passed and 0 failed.Test passed.

Go to answer 3

Question 4

True or False? Given the Python module shown in Figure 13 , execution of the module as a script using the command shown in Figure 14 produces the output shown in Figure 15 .

Figure 13 . Question 4 Python module named Py1359_1720r_04.py.
""" Begin first test>>>sum(2,3) 5Begin second test>>>product(2,3) 6""" def sum(parA,parB):return parA + parB def product(parC,parD):return parC * parD if __name__ == "__main__":import doctest doctest.testmod()
Figure 14 . Question 4 execution command.
python Py1359_1720r_04.py -v
Figure 15 . Question 4 possible output.
Trying: sum(2,3)Expecting: 5ok Trying:product(2,3) Expecting:6 ok2 items had no tests: __main__.product__main__.sum 1 items passed all tests:2 tests in __main__ 2 tests in 3 items.2 passed and 0 failed. Test passed.

Go to answer 4

Question 5

True or False? Given the Python module shown in Figure 16 , execution of the module as a script using the command shown in Figure 17 produces the output shown in Figure 18 .

Figure 16 . Question 5 Python module named Py1359_1720r_05.py.
""">>>divide(2,3) 0>>>divide(2,0) Traceback (most recent call last):... ZeroDivisionError: integer division or modulo by zero""" def divide(parA,parB):return parA//parB if __name__ == "__main__":import doctest doctest.testmod()
Figure 17 . Question 5 execution command.
python Py1359_1720r_05.py -v
Figure 18 . Question 5 possible output.
Trying: divide(2,3)Expecting: 0ok Trying:divide(2,0) Expecting:Traceback (most recent call last): ...ZeroDivisionError: integer division or modulo by zero ok1 items had no tests: __main__.divide1 items passed all tests: 2 tests in __main__2 tests in 2 items. 2 passed and 0 failed.Test passed.

Go to answer 5

Question 6

True or False? Given the Python module shown in Figure 19 , execution of the module as a script using the command shown in Figure 20 produces the output shown in Figure 21 .

Figure 19 . Question 6 Python module named Py1359_1720r_06.py.
""">>>function(11) Traceback (most recent call last):... ValueError: par must be<= 10 """def function(par): if par>10: raise ValueError("par must be<= 10") else:return par if __name__ == "__main__":import doctest doctest.testmod()

Questions & Answers

what are the products of Nano chemistry?
Maira Reply
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
learn
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
learn
Preparation and Applications of Nanomaterial for Drug Delivery
Hafiz Reply
Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
Jyoti Reply
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





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