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

Shuffle Q/A 1

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

Leave a Reply