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

how do you get the 2/50
Abba Reply
number of sport play by 50 student construct discrete data
Aminu Reply
width of the frangebany leaves on how to write a introduction
Theresa Reply
Solve the mean of variance
Veronica Reply
Step 1: Find the mean. To find the mean, add up all the scores, then divide them by the number of scores. ... Step 2: Find each score's deviation from the mean. ... Step 3: Square each deviation from the mean. ... Step 4: Find the sum of squares. ... Step 5: Divide the sum of squares by n – 1 or N.
kenneth
what is error
Yakuba Reply
Is mistake done to something
Vutshila
Hy
anas
hy
What is the life teble
anas
hy
Jibrin
statistics is the analyzing of data
Tajudeen Reply
what is statics?
Zelalem Reply
how do you calculate mean
Gloria Reply
diveving the sum if all values
Shaynaynay
let A1,A2 and A3 events be independent,show that (A1)^c, (A2)^c and (A3)^c are independent?
Fisaye Reply
what is statistics
Akhisani Reply
data collected all over the world
Shaynaynay
construct a less than and more than table
Imad Reply
The sample of 16 students is taken. The average age in the sample was 22 years with astandard deviation of 6 years. Construct a 95% confidence interval for the age of the population.
Aschalew Reply
Bhartdarshan' is an internet-based travel agency wherein customer can see videos of the cities they plant to visit. The number of hits daily is a normally distributed random variable with a mean of 10,000 and a standard deviation of 2,400 a. what is the probability of getting more than 12,000 hits? b. what is the probability of getting fewer than 9,000 hits?
Akshay Reply
Bhartdarshan'is an internet-based travel agency wherein customer can see videos of the cities they plan to visit. The number of hits daily is a normally distributed random variable with a mean of 10,000 and a standard deviation of 2,400. a. What is the probability of getting more than 12,000 hits
Akshay
1
Bright
Sorry i want to learn more about this question
Bright
Someone help
Bright
a= 0.20233 b=0.3384
Sufiyan
a
Shaynaynay
How do I interpret level of significance?
Mohd Reply
It depends on your business problem or in Machine Learning you could use ROC- AUC cruve to decide the threshold value
Shivam
how skewness and kurtosis are used in statistics
Owen Reply
yes what is it
Taneeya
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