Exam 2: Pthon: Estimating PI: Math and Random Methods, Selection and Boolean Expressions, the Print Function

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

When calculating pi using the Wallis formula, the accumulator variable:

(Multiple Choice)
4.9/5
(43)

Case Study 1: >>> import math >>> numSides = 8 >>> innerAngleB = 360.0 / numSides >>> halfAngleA = innerAngleB / 2 >>> oneHalfSideS = math.sin(math.radians(halfAngleA)) >>> sideS = oneHalfSideS * 2 >>> polygonCircumference = numSides * sideS >>> pi = polygonCircumference / 2 >>> pi 3.0614674589207183 -Refer to the session in the accompanying case study 1. Which line uses the math module?

(Multiple Choice)
4.8/5
(38)

To create a drawing window, use the Screen constructor contained in the turtle module.

(True/False)
4.9/5
(43)

How many times will the following print statement be executed? >>> for sides in range(8, 100, 8): Print(sides, archimedes(sides))

(Multiple Choice)
4.9/5
(32)

1. Match each definition with its term. -True or False

(Multiple Choice)
4.9/5
(36)

The parameters passed to the print function are, by default, separated by a space when printed.

(True/False)
4.8/5
(35)

Case Study 1: >>> import math >>> numSides = 8 >>> innerAngleB = 360.0 / numSides >>> halfAngleA = innerAngleB / 2 >>> oneHalfSideS = math.sin(math.radians(halfAngleA)) >>> sideS = oneHalfSideS * 2 >>> polygonCircumference = numSides * sideS >>> pi = polygonCircumference / 2 >>> pi 3.0614674589207183 -Refer to the session in the accompanying Case Study 1. Explain, in general terms, how to modify this series of statements in such a way that you would be able to change the number of sides and try the calculation again without needing to retype all of the statements.

(Essay)
4.8/5
(31)

When using the Wallis function, the larger the value of the parameter passed into the function, the less accurate the result. Therefore, wallis(100) will be more accurate than wallis(10000).

(True/False)
4.8/5
(45)

The ____ statement is used to terminate a function.

(Multiple Choice)
4.8/5
(35)

What is the name of the formula that calculates pi using the following equation? π/4 = 1/1 - 1/3 + 1/5 - 1/7 + 1/9 …

(Multiple Choice)
4.9/5
(38)

Case Study 2: >>> acc = 0 >>> for x in range(1, 6): acc = acc + x >>> acc 15 -Refer to the session in the accompanying case study 2. Which of the following is the initialization statement?

(Multiple Choice)
4.9/5
(33)

The ____ uses probability and random behavior to calculate pi.

(Multiple Choice)
4.8/5
(34)

Explain the term short-circuit evaluation of Boolean expressions. Use an example to illustrate what this means.

(Essay)
4.8/5
(35)
Showing 21 - 33 of 33
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)