python for data science ai & development coursera week 3 quiz answers

Practice Quiz

1. what is the result of the following: 1=2

  • False
  • True
  • SyntaxError:can’t assign to literal

2. What is the output of the following code segment:

i=6

i<5

  • True
  • False
  • SyntaxError: can’t assign to literal

3. What is the result of the following: 5!=5

  • False
  • True

4. What is the output of the following code segment: 'a'=='A'

  • False
  • True

5. in the video, if age=18 what would be the result

  • move on
  • you can enter

6. in the video what would be the result if we set the variable age as follows: age= -10

  • o see Meat Loaf

    move on

  • you can enter

    move on

7. what is the result of the following: True or False

  • True, an or statement is only False if all the Boolean values are False
  • False

8. what will be the output of the following:

for x in range(0,3):

print(x)

  • 0

    1

    2

  • 0

    1

    2

    3

9. what is the output of the following:

for x in ['A','B','C']:
print(x+'A')

  • AA

    BA

    CA

  • A

    B

    C

10. what is the output of the following:

for i,x in enumerate(['A','B','C']):

print(i,x)

  • 0 A

    1 B

    2 C

  • AA

    BB

    CC

11. What does the following function return: len(['A','B',1]) ?

  • 3
  • 2
  • 4

12. What does the following function return: len([sum([0,0,1])]) ?

  • 1
  • 0
  • 3

13. What is the value of list L after the following code segment is run :

L=[1,3,2]

sorted(L)

  • L:[1,3,2]
  • L:[1,2,3]
  • L:[0,0,0]

14. From the video what is the value of c after the following:

c=add1(2)

c=add1(10)

  • 3
  • 11
  • 14

15. what is the output of the following lines of code:

def Print(A):

for a in A:

print(a+'1')

Print(['a','b','c'])

  • a

    b

    c

  • a1

    b1

    c1

  • a1

16. Why do we use exception handlers?

  • Read a file
  • Terminate a program
  • Write a file
  • Catch errors within a program

17. What is the purpose of a try…except statement?

  • Only executes if one condition is true
  • Crash a program when errors occur
  • Catch and handle exceptions when an error occurs
  • Executes the code block only if a certain condition exists

18. What is the type of the following?

["a"]

  • str
  • list

19. What does a method do to an object?

  • Changes or interacts with the object
  • Returns a new values

20. We create the object: Circle(3,'blue') What is the color attribute set to?

  • 2
  • ‘blue’

21. What is the radius attribute after the following code block is run?

RedCircle=Circle(10,'red')

RedCircle.radius=1

  • 10
  • 1
  • ‘red’

22. What is the radius attribute after the following code block is run?

BlueCircle=Circle(10,'blue')

BlueCircle.add_radius(20)

  • 10
  • 20
  • 30

Module 3 Graded Quiz

23. What is the output of the following code?

x="Go"

if(x=="Go"):

print('Go ')

else:

print('Stop')

print('Mike')

  • Go Mike
  • Mike
  • Stop Mike

24. What is the result of the following lines of code?

x=1
x>-5

  • True
  • False

25. What is the output of the following few lines of code?

x=5
while(x!=2):
print(x)
x=x-1

  • 5

    4

    3

  • 5

    4

    3

    2

  • the program will never leave the loop

26. What is the result of running the following lines of code ?

class Points(object):
def __init__(self,x,y):

self.x=x
self.y=y

def print_point(self):

print('x=',self.x,' y=',self.y)

p1=Points("A","B")
p1.print_point()

  • x= A
  • y= B
  • x= A y= B

27. What is the output of the following few lines of code?

for i,x in enumerate(['A','B','C']):
print(i,2*x)

  • 0 AA

    1 BB

    2 CC

  • 0 A

    1 B

    2 C

  • 0 A

    2 B

    4 C

28. What is the result of running the following lines of code ?

class Points(object):
def __init__(self,x,y):

self.x=x
self.y=y

def print_point(self):

print('x=',self.x,' y=',self.y)

p2=Points(1,2)

p2.x=2

p2.print_point()

  • x=2 y=2
  • x=1 y=2
  • x=1 y=1

29. Consider the function step, when will the function return a value of 1?

def step(x):
if x>0:
y=1
else:
y=0
return y

  • if x is larger than 0
  • if x is equal to or less then zero
  • if x is less than zero

30. What is the output of the following lines of code?

a=1

def do(x):
a=100
return(x+a)

print(do(1))

  • 2
  • 101
  • 102

31. Write a function name add that takes two parameter a and b, then return the output of a + b (Do not use any other variable! You do not need to run it. Only write the code about how you define it.)

32. Why is it best practice to have multiple except statements with each type of error labeled correctly?

  • Ensure the error is caught so the program will terminate
  • In order to know what type of error was thrown and the location within the program
  • To skip over certain blocks of code during execution
  • It is not necessary to label errors

Leave a Reply