get started with python coursera week 3 quiz answers

Test your knowledge: While loops

1. Fill in the blank: A while loop instructs your computer to continuously execute your code based on the value of a _____.

  • condition
  • comparator
  • data type
  • function

2. A data professional wants to set up a while loop that will iterate as long as the variable x is less than 7. They assign the value 0 to the variable x. What code should they write next?

  • loop x < 7:
  • repeat x < 7:
  • while x < 7:
  • iterate x < 7:

3. In Python, the keyword break lets you escape a loop without triggering any else statement that follows it in the loop.

  • True
  • False

Test your knowledge: For loops

4. A data professional can use a for loop to perform which of the following tasks?

  • To repeat a specific block of code until a condition is met
  • To convert one data type to another
  • To iterate over a series of numbers
  • To define a function

5. A data professional wants to set up a for loop. They write the following code: for x in range(3): . What values will the variable x take?

  • 0, 1, and 2
  • 1, 2, and 3
  • Only 3
  • 0, 1, 2, and 3

6. What parameter of Python’s range() function specifies the size of the increments in a sequence of numbers?

  • Stop value
  • Loop value
  • Step value
  • Start value

Test your knowledge: Strings

7. In Python, what is the term for the portion of a string that can contain more than one character? Select all that apply.

  • String slice
  • Substring
  • String segment
  • Superstring

8. If you’re reading from left to right, what is the index of the first character in a string?

  • 0
  • 1
  • 2
  • 3

9. A data professional wants to insert specific substrings in a larger string. What method can they use to do so?

  • type()
  • range()
  • format()
  • print()

Weekly challenge 3

10. A data professional can use a while loop to perform which of the following tasks?

  • To repeat a specific block of code until a condition is met
  • To define a function
  • To convert one data type to another
  • To iterate over a sequence of values

11. Fill in the blank: The Python _____ function returns a sequence of numbers starting from zero; then increments by one, by default; then stops before the given number.

  • type()
  • range()
  • format()
  • index()

12. What Python code instructs the computer to loop through values from 750 to 850?

  • for x in range(750, 851):
  • for x in range(750, 850):
  • for x in range(751, 851):
  • for x in range(751, 850):

13. A data professional wants to set up a for loop. They write the following code: for x in range(5, 101, 10): . What is the step value of the range() function?

  • 5
  • 100
  • 10
  • 101

14. What Python code can a data professional use to concatenate the strings 'air' and 'plane'?

  • ‘air’ % ‘plane’
  • ‘air’ + ‘plane’
  • ‘air’ / ‘plane’
  • ‘air’ == ‘plane’

15. A data professional wants to identify the location of a character in a string. What Python method can they use to do so?

  • print()
  • index()
  • format()
  • range()

16. A data professional assigns the string 'palm and pine' to the variable trees. What Python code can they use to find the index of the character 'm'?

  • trees.index(‘m’)
  • index.trees(‘m’)
  • index.palm(‘m’)
  • palm.index(‘m’)

17. A data professional assigns the string 'classical' to the variable genre. What Python code will return the slice 'class'?

  • genre[1:5]
  • genre[ :5]
  • genre[5: ]
  • genre[-1]

18. Fill in the blank: In Python, a data professional can use the _____ method to insert specific substrings in a larger string.

  • print()
  • range()
  • format()
  • type()

19. Fill in the blank: A data professional can use a _____ to repeat a specific block of code until a condition is met.

  • for loop
  • while loop
  • else loop()
  • if loop

20. Fill in the blank: The Python range() function returns a sequence of numbers starting from zero; then increments by _____, by default; then stops before the given number.

  • one
  • two
  • zero
  • three

21. What Python code instructs the computer to loop through values from 100 to 500?

  • for x in range(100, 501):
  • for x in range(100, 500):
  • for x in range(101, 501):
  • for x in range(101, 500):

22. A data professional wants to set up a for loop. They write the following code: for x in range(100, 501, 20): . What is the step value of the range() function?

  • 20
  • 500
  • 100
  • 501

23. Fill in the blank: In Python, the index() method interprets a string as a _____.

  • boolean
  • substring
  • sequence of characters
  • string slice

24. A data professional assigns the string 'spinach and asparagus' to the variable vegetables. What code can they use to find the index of the character 'c'?

  • spinach.index(‘c’)
  • index.vegetables(‘c’)
  • vegetables.index(‘c’)
  • index.spinach(‘c’)

25. A data professional assigns the string 'football' to the variable sport. What Python code will return the slice 'ball'?

  • sport[ :4]
  • sport[1:4]
  • sport[4: ]
  • sport[-1]

26. What type of loop can a data professional use to repeat a specific block of code until a condition is met?

  • if loop
  • for loop
  • else loop
  • while loop

27. What Python code can a data professional use to concatenate the strings 'jelly' and 'fish'?

  • ‘jelly’ + ‘fish’
  • ‘jelly’ < ‘fish’
  • ‘jelly’ > ‘fish’
  • ‘jelly’ == ‘fish’

28. In Python, what method works by interpreting a string as a sequence of characters, where each character has a numbered slot?

  • format()
  • range()
  • type()
  • index()

29. Fill in the blank: A data professional can use the format() method to insert specific _____ in a larger string.

  • substrings
  • for loops
  • while loops
  • libraries

30. A data professional wants to set up a for loop. They write the following code: for x in range(0, 26, 5): . What is the step value of the range() function?

  • 25
  • 26
  • 0
  • 5

31. What Python code can a data professional use to concatenate the strings 'brain' and 'storm'?

  • ‘brain’ % ‘storm’
  • ‘brain’ != ‘storm’
  • ‘brain’ == ‘storm’
  • ‘brain’ + ‘storm’

Leave a Reply