Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

FOR PYTHON Write a creative PYTHON program as follows to demonstrate your unders

ID: 3800291 • Letter: F

Question

FOR PYTHON

Write a creative PYTHON program as follows to demonstrate your understanding of Python lists:

Start by making an empty list.

Use a loop to add twelve random integers between 50 and 80, inclusive, to the list.

Sort the list in descending order from highest to lowest.

Use a loop to print the sorted list elements on one line separated by single spaces.

Determine if 66 is in the list and generate some appropriate output. See SAMPLE OUTPUT.

Print the largest element in the list and the smallest element in the list.

Slice out the five elements with indexes 4 through 8 and assign to a variable. Print the slice.

Print the total of all five elements in this slice.

Use a while loop to display all elements in the slice on one line separated by tabs.

SAMPLE OUTPUT

71 70 67 66 62 55 53 52 52 52 51 50

Yes, 66 is in the list at index 3

71 is the largest element

The smallest element is 50

Here is the slice [62, 55, 53, 52, 52]

The total of the slice is 274

62 55 53 52 52

Explanation / Answer

import random def main (): # Create values. vals = [] for x in range(12): vals.append(random.randint(50,80)) vals.sort(reverse=True) # Compute some stuff. max_val = max(vals) min_val = min(vals) has_66 = 66 in vals vals_slice = vals[4:9] # Elements 4 through 8, inclusive. sum_slice = sum(vals_slice) # Print stuff. ... main()