Answered step by step
Verified Expert Solution
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...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started