Description
Perform the following tasks on your lab machine:
1. Create a list with the following numbers (100, 300, 500, 2300, 2500) using the range function and answer the following:
a. Print the length of the list
b. Print the elements in the list such that each element appears in a separate line
c. Print the average of all the items in the list
d. Replace the maximum element of the list with the average value of the list
e. Insert a new element at index 7. The value of the new element is the nth root of the value that is located in the middle of the list. Take n from the user.
f. Write a for loop to print the last 3 elements in the list in reverse order
g. Divide the list into two new lists where the first 3 elements will be in list X and the remaining elements will be in list Y. Print both lists.
2. Create two empty dictionaries dict1 and dict2:
a. Create dict1. dict1 has two keys: ‘car type’ and ‘size’. The value of each field is obtained from the user.
b. Create dict2. dict2 has three keys: ‘engine’, ‘origin’, and ‘date of release’. The value of each field is obtained from the user. The value of “date of release” is a dictionary {‘day’: value, ‘month’: value, ‘year’: value].
c. Add another field ‘color’ to dict1 and initialize it with your favorite color.
d. Using the values stored in dict1 and dict2, print the following statement: “The car type is considered a size car. It has an engine CC engine. It is released on day/month/year”.
e. Merge both dictionaries into one dictionary called dict.
f. Use the keys() method to print the following sentence: “The keys of dict2 are: engine, origin, and date of release”.
Bob Salerno –
Excellent, thank you! Got solution extremely fast, within minutes.
Brian Duke –
Very impressive work and way ahead of time! Thanks!