INSY 3300
Which mathematical operator is used to raise 5 to the second power in Python? a. / b. ** c. ^ d. ~
**
What will the following statement do? print(random.uniform(0.1, 0.5))
0.4189640405191005 (Any number between .1 through .5)
What will be the following program display? def main(): x = 1 y = 3.4 print(x, y) change_us(x, y) print(x, y) def change_us(a, b): a = 0 b= 0 print(a, b) main()
1 3.4, 0 0, 1 3.4
What are the values that the variable num contains through the iterations of the following for loop? for num in range(10, 1, -1):
10, 9, 8, 7, ....2
What are the values that the variable num contains through the iterations of the following for loop? for num in range(2, 9, 2):
2, 4, 6, 8
Look at the following function definition : def class_function(a, b, c) d = (a+c) /b print(d) b)What will be the value displayed when this function call is executed?
2.0
What is the output of the following statement, given that value1 = 2.0 and value2 = 12?print(value1 * value2) a. 24 b. value1 * value2 c. 24.0 d. 2.0 * 12
24.0
What will display after the following code is executed? def main(): print("The answer is", magic(5)) def magic(num): answer = num + 2 * 10 return answer main()
25
What are the values that the variable num contains through the iterations of the following for loop? for num in range(4):
4 iterations having the values of 0, 1, 2, 3
What will be displayed after the following code is executed? total = 0 for count in range(1,4): total += count print(total)
6
What will be the output after the following code is executed? def pass_it(x, y): z = y**x return(z) num1 = 3 num2 = 4 answer = pass_it(num1, num2) print(answer)
64
Select all that apply. To create a Python program you can use a. a text editor b. a word processor if you save your file as a .docx c. IDLE d. Excel
A Text Editor IDLE
In a print statement, you can set the __________ argument to a space or empty string to stop the output from advancing to a new line. a. stop b. end c. separator d. newLine
End
A local variable can be accessed from anywhere in the program
False
Python allows you to compare strings, but it is not case sensitive
False
Python formats all floating-point numbers to two decimal places when outputting with the print statement
False
The Python language uses a compiler which is a program that both translates and executes the instructions in a high-level language.
False
The __________ function reads a piece of data that has been entered at the keyboard and returns that piece of data, as a string, back to the program. a. input() b. output() c. eval_input() d. str_input()
Input()
What are logical and relational operators?
Logical: and, or, not Relational :==, <=, >= , etc
What is the output of the following statement?print('One' 'Two' 'Three') a. One Two Three b. One Two Three c. OneTwoThree d. Nothing—This statement contains an error.
OneTwoThree
Which type of error prevents the program from running? a. syntax b. human c. grammatical d. logical
Syntax
A value-returning function is like a simple function except that when it finishes it returns a value back to the part of the program that called it.
True
Computer programs typically perform three steps: input is received, some process is performed on the input, and output is produced.
True
Expressions that are tested by the if statement are called Boolean expressions.
True
IDLE is an alternative method to using a text editor to write, execute, and test a Python program
True
In Python, print statements written on separate lines do not necessarily output on separate lines.
True
RAM is a volatile memory used for temporary storage while a program is running.
True
The function header marks the beginning of the function definition.
True
What is the result of the following Boolean expression, given that x = 5, y = 3, and z = 8? x < y or z > x (T/F)
True
What will be displayed after the following code is executed? count = 4 while count < 12: print("counting") count = count + 2
counting counting counting counting
Write an if clause to determine whether x is anything other than 10?
if x != 10:
Write an if-else statement that assigns 0 to the variable y if the variable x is less than 10. Otherwise it should assign 99 to the variable y.
if x <10: y = 0 else: y = 99
Write nested decision structures that perform the following: if x is greater than 10 and y is less than 100, display the greater of x and y.
if x > 10 and y < 100: if x > y: print(x) elif y > x: print (y) else: print( ' both values are the same')
Which of the following is the correct if clause to determine whether y is in the range 10 through 50, inclusive? a. if 10 < y or y > 50: b. if 10 > y and y < 50: c. if y >= 10 and y <= 50: d. if y >= 10 or y <= 50:
if y >= 10 and y <= 50:
Write a statement that generate a random number between 1 through 100 and assign it to a variable named rand
import random rand = random.randint(1, 100)
How many numbers of loop iterations will the following code will execute? x = 99 while x > 0: print (x)
it is an example of Infinite loop. No code is written inside the loop that makes the test condition false.
Look at the following function definition : def class_function(a, b, c) d = (a+c) /b print(d) a) Write a function and use keyword argument to pass 2 into a, 4 into b, 6 into c.
my_function (a = 2, b = 4, c = 6)