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

Practice Quiz

1. Consider the following tuple:

say_what=('say',' what', 'you', 'will')

what is the result of the following say_what[-1]

  • ‘you’
  • ‘ what’
  • ‘will’
  • ‘say’

2. Consider the following tuple A=(1,2,3,4,5). What is the result of the following: A[1:4]:

  • (2, 3, 4,5)
  • (2, 3, 4)
  • (3, 4,5)

3. Consider the following tuple A=(1,2,3,4,5), what is the result of the following: len(A)

  • 4
  • 5
  • 6

4. Consider the following list B=[1,2,[3,'a'],[4,'b']], what is the result of the following:B[3][1]

  • “c”
  • “b”
  • [4,”b”]

5. What is the result of the following operation?

[1,2,3]+[1,1,1]

  • [1, 2, 3, 1, 1, 1]
  • TypeError
  • [2,3,4]

6. What is the length of the list A = [1] after the following operation: A.append([2,3,4,5])

  • 2
  • 6
  • 5

7. What is the result of the following: "Hello Mike".split()

  • [“HelloMike”]
  • [“Hello”,”Mike”]
  • [“H”]

8. What are the keys of the following dictionary: {"a":1,"b":2}

  • 1,2
  • “a”,”b”

9. Consider the following Python Dictionary:

Dict={"A":1,"B":"2","C":[3,3,3],"D":(4,4,4),'E':5,'F':6}

What is the result of the following operation: Dict["D"]

  • [3,3,3]
  • (4, 4, 4)
  • 1

10. Consider the following set: {"A","A"}, what will the result be when the set is created?

  • {“A”}
  • {“A”,”A”}

11. What is the result of the following: type(set([1,2,3]))

  • set
  • list

12. What method do you use to add an element to a set?

  • extend
  • add
  • append

13. What is the result of the following operation : {'a','b'} &{'a'}

  • {‘a’,’b’}
  • {‘a’}

Module 2 Graded Quiz

14. Consider the tuple A=((1),[2,3],[4]), that contains a tuple and list. What is the result of the following operation A[2] ?

  • [4]
  • [2,3]
  • 1

15. Consider the tuple A=((11,12),[21,22]), that contains a tuple and list. What is the result of the following operation A[0][1]?

  • 21
  • 11
  • 12

16. The method append does the following:

  • adds one element to a list
  • merges two lists or insert multiple elements to a list

17. Consider the following list : A=["hard rock",10,1.2]

What will list A contain after the following command is run: del(A[0]) ?

  • [10,1.2]
  • [“hard rock”,10,1.2]
  • [“hard rock”,10]

18. What is the syntax to clone the list A and assign the result to list B ?

  • B=A
  • B=A[:]

19. What is the result of the following: len(("disco",10,1.2, "hard rock",10)) ?

  • 5
  • 6
  • 0

20. Consider the following dictionary:

{ "The Bodyguard":"1992", "Saturday Night Fever":"1977"}

select the values

  • “1977”
  • “1992”
  • “The Bodyguard”
  • “Saturday Night Fever”

21. The variable release_year_dict is a Python Dictionary, what is the result of applying the following method: release_year_dict.values() ?

  • retrieve the keys of the dictionary
  • retrieves, the values of the dictionary

22. Consider the Set: V={'A','B'}, what is the result of V.add('C')?

  • error
  • {‘A’,’B’}
  • {‘A’,’B’,’C’}

23. What is the result of the following: '1' in {'1','2'} ?

  • False
  • True

Leave a Reply