Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A list called ages has been created in Python. There are two values out of order in the list and these values are stored

 

A list called ages has been created in Python. There are two values out of order in the list and these values are stored at indexes 0 and 2. Write code to swap those two values so that the list would be in order. The following questions refer to a list called fantasy. You do not know what values are stored in fantasy, and you do not how many elements fantasy contains, except there is at least one. In the box below, write Python code to print the first element of the list fantasy. In the box below, write Python code to print the final element of the list fantasy. The code block below operates on the list fantasy. The variable index contains an unknown value but it is known that: 0 index < the length of the list fantasy (ie it is a valid position). The code prints out the value of the list element one place to the left of fantasy [index], but if there is no element to the left of fantasy [index], it prints an appropriate error message: if index > 0: print (fantasy [index - 1]) else: print ('nothing to the left') In the box below, write Python code to print out the value of the list element one place to the right of fantasy [index], but if there is no element to the right of fantasy [index], it prints an appropriate error message. As for the code above, it is known that: 0 index < the length of the list fantasy. Write an if statement that compares the values in fantasy at index and the value in fantasy one place to the right, and prints out the larger of those two values (or either of them if they are equal). It is known that: 0 index < one less than the length of the list fantasy so your code should not test for that.

Step by Step Solution

3.47 Rating (160 Votes )

There are 3 Steps involved in it

Step: 1

1 We are going to solve the first question using func... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Business Communication

Authors: Mary Ellen Guffey, Dana Loewy

9th edition

978-0132555500, 132555506, 978-1111821227

Students also viewed these Computer Engineering questions

Question

Let A and B be two events in a sample space with A B. Then, A B = .

Answered: 1 week ago

Question

What is an access control list?

Answered: 1 week ago

Question

Why are reports indispensable documents in business?

Answered: 1 week ago