Deck 2: Pthon: Estimating PI: Math and Random Methods, Selection and Boolean Expressions, the Print Function
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/33
العب
ملء الشاشة (f)
Deck 2: Pthon: Estimating PI: Math and Random Methods, Selection and Boolean Expressions, the Print Function
1
In order to use the sqrt() function, you must use which of the following Python statements?
A) use math;
B) import math;
C) math::sqrt();
D) return sqrt();
A) use math;
B) import math;
C) math::sqrt();
D) return sqrt();
B
2
Which of the following is a constant in the math module?
A) sqrt
B) tan
C) asin
D) e
A) sqrt
B) tan
C) asin
D) e
D
3
What equation relates pi to the circumference of a circle?
A) C = 2πr (where r is the radius of the circle)
B) C = πr (where r is the radius of the circle)
C) C = 2πd (where d is the diameter of the circle)
D) C = 2πa (where a is the area of the circle)
A) C = 2πr (where r is the radius of the circle)
B) C = πr (where r is the radius of the circle)
C) C = 2πd (where d is the diameter of the circle)
D) C = 2πa (where a is the area of the circle)
A
4
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?
A) innerAngleB = 360.0 / numSides
B) oneHalfSideS = math.sin(math.radians(halfAngleA))
C) pi = polygonCircumference / 2
D) sideS = oneHalfsideS * 2
>>> 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?
A) innerAngleB = 360.0 / numSides
B) oneHalfSideS = math.sin(math.radians(halfAngleA))
C) pi = polygonCircumference / 2
D) sideS = oneHalfsideS * 2
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
5
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. How many sides does the polygon in this approximation have?
A) 2
B) 8
C) 64
D) pi
>>> 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. How many sides does the polygon in this approximation have?
A) 2
B) 8
C) 64
D) pi
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
6
The ____ statement is used to terminate a function.
A) return
B) exit
C) end
D) quit
A) return
B) exit
C) end
D) quit
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
7
How many times will the following print statement be executed?
>>> for sides in range(8, 100, 8):
Print(sides, archimedes(sides))
A) 1
B) 8
C) 12
D) 16
>>> for sides in range(8, 100, 8):
Print(sides, archimedes(sides))
A) 1
B) 8
C) 12
D) 16
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
8
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?
A) acc
B) for x in range(1, 6):
C) acc = acc + x
D) acc = 0
>>> 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?
A) acc
B) for x in range(1, 6):
C) acc = acc + x
D) acc = 0
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
9
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. What type of variable is acc?
A) Accumulator variable
B) Range variable
C) Initialization variable
D) Timer variable
>>> acc = 0
>>> for x in range(1, 6):
acc = acc + x
>>> acc
15
-Refer to the session in the accompanying case study 2. What type of variable is acc?
A) Accumulator variable
B) Range variable
C) Initialization variable
D) Timer variable
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
10
What is the name of the formula that calculates pi using the following equation?
&It;font_face=symbol> &It;/font>/4 = 1/1 - 1/3 + 1/5 - 1/7 + 1/9 …
A) Archimedes approach
B) Leibniz formula
C) Wallis formula
D) Monte Carlo simulation
&It;font_face=symbol> &It;/font>/4 = 1/1 - 1/3 + 1/5 - 1/7 + 1/9 …
A) Archimedes approach
B) Leibniz formula
C) Wallis formula
D) Monte Carlo simulation
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
11
When calculating pi using the Wallis formula, the accumulator variable:
A) must be initialized to zero.
B) is increased by two each iteration.
C) must be initialized to one.
D) is multiplied by two each iteration.
A) must be initialized to zero.
B) is increased by two each iteration.
C) must be initialized to one.
D) is multiplied by two each iteration.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
12
The ____ uses probability and random behavior to calculate pi.
A) Archimedes approach
B) Leibniz formula
C) Wallis formula
D) Monte Carlo simulation
A) Archimedes approach
B) Leibniz formula
C) Wallis formula
D) Monte Carlo simulation
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
13
To create a random number in Python, use the ____ function.
A) math.random()
B) random.random()
C) montecarlo.random()
D) help.random()
A) math.random()
B) random.random()
C) montecarlo.random()
D) help.random()
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
14
The relational operator that means "not equal" is represented with which operator in Python?
A) ==
B) !=
C) &It;=
D) >=
A) ==
B) !=
C) &It;=
D) >=
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
15
Case Study 3:
1. if &It;condition>:
2. if &It;condition>:
3. &It;statements>
4. else:
5. &It;statements>
6. else:
7. if &It;condition>:
8. &It;statements>
9. else:
10. &It;statements>
-Refer to the code in the accompanying case study. Under what circumstances are the statements on line 10 executed?
A) The condition in line 1 is false, and the condition in line 7 is false.
B) The condition in line 1 is false, and the condition in line 7 is true.
C) The condition in line 1 is true, and the condition in line 7 is false.
D) The condition in line 1 is true, and the condition in line 7 is true.
1. if &It;condition>:
2. if &It;condition>:
3. &It;statements>
4. else:
5. &It;statements>
6. else:
7. if &It;condition>:
8. &It;statements>
9. else:
10. &It;statements>
-Refer to the code in the accompanying case study. Under what circumstances are the statements on line 10 executed?
A) The condition in line 1 is false, and the condition in line 7 is false.
B) The condition in line 1 is false, and the condition in line 7 is true.
C) The condition in line 1 is true, and the condition in line 7 is false.
D) The condition in line 1 is true, and the condition in line 7 is true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
16
The parameters passed to the print function are, by default, separated by a space when printed.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
17
The code in the accompanying case study 2 (see below) is used to calculate a running product.
>>> acc = 0
>>> for x in range(1, 6):
acc = acc + x
>>> acc
15
>>> acc = 0
>>> for x in range(1, 6):
acc = acc + x
>>> acc
15
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
18
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).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
19
Another name for an if statement is a selection statement.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
20
To create a drawing window, use the Screen constructor contained in the turtle module.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
21
1. Match each definition with its term.
-True or False
A) Boolean values
B) Selection statement
C) Logical operators
D) Relational expressions
-True or False
A) Boolean values
B) Selection statement
C) Logical operators
D) Relational expressions
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
22
1. Match each definition with its term.
-Contains a question and other groups of statements that may or may not be executed, depending on the result of the question.
A) Boolean values
B) Selection statement
C) Logical operators
D) Relational expressions
-Contains a question and other groups of statements that may or may not be executed, depending on the result of the question.
A) Boolean values
B) Selection statement
C) Logical operators
D) Relational expressions
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
23
1. Match each definition with its term.
-and, or, and not
A) Boolean values
B) Selection statement
C) Logical operators
D) Relational expressions
-and, or, and not
A) Boolean values
B) Selection statement
C) Logical operators
D) Relational expressions
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
24
1. Match each definition with its term.
-Compares two data values.
A) Boolean values
B) Selection statement
C) Logical operators
D) Relational expressions
-Compares two data values.
A) Boolean values
B) Selection statement
C) Logical operators
D) Relational expressions
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
25
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.
>>> 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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
26
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. Explain what pattern this code implements and why it is useful.
>>> acc = 0
>>> for x in range(1, 6):
acc = acc + x
>>> acc
15
-Refer to the session in the accompanying Case Study 2. Explain what pattern this code implements and why it is useful.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
27
What are some patterns to keep in mind when implementing the Leibniz formula with Python?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
28
Explain how a Monte Carlo simulation can be used to calculate the value of pi.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
29
Explain the difference between the "=" in line 1 and the "==" in line 2 in the code sample below:
1. >>> apple = 25
2. >>> apple == 25
3. True
1. >>> apple = 25
2. >>> apple == 25
3. True
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
30
Explain the term short-circuit evaluation of Boolean expressions. Use an example to illustrate what this means.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
31
Why are decisions referred to as "selection" in computer science?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
32
Case Study 3:
1. if &It;condition>:
2. if &It;condition>:
3. &It;statements>
4. else:
5. &It;statements>
6. else:
7. if &It;condition>:
8. &It;statements>
9. else:
10. &It;statements>
-Refer to the code in the accompanying Case study 3. Why is this section of code referred to as "nested selection"?
1. if &It;condition>:
2. if &It;condition>:
3. &It;statements>
4. else:
5. &It;statements>
6. else:
7. if &It;condition>:
8. &It;statements>
9. else:
10. &It;statements>
-Refer to the code in the accompanying Case study 3. Why is this section of code referred to as "nested selection"?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck
33
Explain how to modify the coordinate system of the drawing window when using the turtle module.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 33 في هذه المجموعة.
فتح الحزمة
k this deck