quiz 3 Flashcards
1
Q
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)
A
1 3.4
0.0
2
Q
Look at the following function definition: def class_function(a, b, c)
d = (a+c) /b print(d) Write a function and use keyword argument to pass 2 into a, 4 into b, 6 into c.
A
my_function(a=2, c=6, b=4)
3
Q
Look at the following function definition: def class_function(a, b, c)
d = (a+c) /b print(d) What will be the value displayed when this function call is executed?
A
2.0
4
Q
print(random.uniform(0.1, 0.5))
A
It prints a random floating-point number in the range of 0.1 through 0.5.
5
Q
Write a statement that generate a random number between 1 through 100 and assign it to a variable named rand
A
rand = random.randint(1, 101)
6
Q
def main():
print("The answer is", magic(5))
def magic(num):
answer = num + 2 * 10 return answer
main()
A
25
7
Q
def pass_it(x, y):
z = y**x return(z)
num1 = 3
num2 = 4
answer = pass_it(num1, num2)
print(answer)
A
64
8
Q
- How many types of files are there to be used in a program?
A
two
text , binary
9
Q
- Which method could be used to strip specific characters from the end of a string?
A
ANS: rstrip(), readline(), read()
10
Q
- Which method will return an empty string when it has attempted to read beyond the end of a file?
A
ANS: readline()
11
Q
- Which statement can be used to handle some of the runtime errors in a program?
A
ANS: try/except
12
Q
- Given that the customer file references a file object, and the file was opened using the ‘w’ mode specifier, how would you write the string ‘Mary Smith’ to the file?
A
ANS: customer.write(‘Mary’ Smith’)