Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

7. function used to return a random integer between (and including) the…

Question

  1. function used to return a random integer between (and including) the two integers we give it. in this chapter, we give it the integers 1 and 20. random.randint(1, 20) argument(s) programming int() 8. what does the .split() method do? splits up a function in two parts so that the computer can evaluate it quicker. it changes a long string into a list, with each word separated by a space making up a single list item. it breaks up a list into two or more lists. the arguments you pass into it determine where the split occurs and what the names of the lists will be. 9. what will be the value of the variable selection? cheese = mozzarella, cheddar, provolone, caprice des dieux selection = cheese1: mozzarella, cheddar, provolone, caprice des dieux caprice des dieux cheddar cheddar, provolone, caprice des dieux provolone

Explanation:

Brief Explanations
  1. In Python, the random.randint(a, b) function returns a random integer N such that a <= N <= b. So random.randint(1, 20) returns a random integer between 1 and 20.
  2. The .split() method in Python takes a string and splits it into a list. By default, it splits on whitespace, making each word separated by a space an item in the list.
  3. In Python list slicing, list[start:] starts from the start - index (inclusive) and goes to the end of the list. For cheese = ['mozzarella', 'cheddar', 'provolone', 'caprice des dieux'], cheese[1:] starts from index 1 (the second element 'cheddar') and includes all elements after it.

Answer:

  1. random.randint(1, 20)
  2. It changes a long string into a list, with each word separated by a space making up a single list item.
  3. ['cheddar', 'provolone', 'caprice des dieux']