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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

def main():

print("The answer is", magic(5))

def magic(num):

answer = num + 2 * 10

return answer

main()

A

25

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. How many types of files are there to be used in a program?
A

two

text , binary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. Which method could be used to strip specific characters from the end of a string?
A

ANS: rstrip(), readline(), read()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Which method will return an empty string when it has attempted to read beyond the end of a file?
A

ANS: readline()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. Which statement can be used to handle some of the runtime errors in a program?
A

ANS: try/except

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. 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’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly