QUESTION IMAGE
Question
- 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
Brief Explanations
- In Python, the
random.randint(a, b)function returns a random integer N such thata <= N <= b. Sorandom.randint(1, 20)returns a random integer between 1 and 20. - 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. - In Python list slicing,
list[start:]starts from thestart- index (inclusive) and goes to the end of the list. Forcheese = ['mozzarella', 'cheddar', 'provolone', 'caprice des dieux'],cheese[1:]starts from index 1 (the second element 'cheddar') and includes all elements after it.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
- random.randint(1, 20)
- It changes a long string into a list, with each word separated by a space making up a single list item.
- ['cheddar', 'provolone', 'caprice des dieux']