<< 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 is the meaning of an idiosyncratic pattern
Krystle Reply
I am here for the first time just here to learn...
michael Reply
hi I'm new on here first time
Lisa
hello
GOPAL
hi,am new here
jennifer
what is this group all about
jennifer
Suppose an individual with OCD experiences obsessive thoughts about germs, contamination, and disease whenever she encounters a doorknob. What might have constituted a viable unconditioned stimulus? 
la Reply
What are factors that influence learning?
Enos Reply
Environment Heredity(I am not sure about heredity)
Tusita
Helpful. .. thanks
Enos
Sure, anytime
Tusita
I have other questions also
Enos
Based on the factors affecting learning, how do we improve learning
Enos
I think that addressing that everyone learns in their own time
James
Peer group influence can also be another reason
Sorie
Also knowing what's going on at home. what pressure are the parents putting on them.
James
am I close or no
James
also is there a lack of care? going one more step. with peer groups do an activity that shows how much they have in common
James
under what schedule of reinforcement do animals learn from ?
Phelisa Reply
the role of emotional intelligence in a courtship behavior
Caren Reply
1
describe the task and roles of industrial psychologist in solving the problems
Solomzi Reply
hi I'm Vaishnavi and I'm new to psychology:)
Vaishnavi Reply
what is motivation
Muhammad Reply
getting passionate about something and strive for success
Leanne
observation and method based
Winter Reply
the meaning of science
Winter
soul is the Greek word for psyche
Winter
psychology is scientific research of the human brain.
Winter
Psychology is a study of human mind and behaviour
Vaishnavi
psychology is a social science which aim at studying the mind as it affect the behavior of an individual.
Prince
write and explain four psychosexual stages of personality development
MPHID Reply
I'm asking on behalf of someone How can a guy get over his weakness for girls? Like the person have soft spot for every girl and he thinks he love them then suddenly stuff change.... Like a switch
Ajayi Reply
yes
Beverly
whats the age of the boy?
Beverly
16 or 17
Ajayi
lol. it gets over with time. it's not something that can be changed instantly. and for teenagers.. anyone of opposite sex is a tasty lollipop.
Alex
yes in time it will go away but could also take years
Beverly
maybe because he doesn't really have mind of making decisions at the moment on what he need and what he doesn't want
Nwokwu
maybe he's trying to find someone to love because he's either lacked loved and feel that's the only way to feel loved or he's lonely and feels a girl can make it better . either he's got deal with the core issue
Jonan
its natural. I think it should be like this. girls also have weakness toward guys. but you can overcome on few things like concept of beauty. first step is realisation which will grow in you. also discipline help in these things.
Sujeet
what are cluster A disease?
Saee Reply
because psychology is a natural science as well as a science. it's a interdisciplinary subject
Kamakshi Reply
yes absolutely we cabt out Psychology completely into science dur to its various measuring aspects
utkarsh
cannot* put*
utkarsh
Assess the relationship between heredity and environment in human development
Newman Reply
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