In: Computer Science
Write a Python program that has a list of 5 numbers [2, 3, 4, 5, 6). Print the first 3 elements from the list using slice expression. a. Extend this program in a manner that the elements in the list are changed to (6, 9, 12, 15, 18) that means each element is times 3 of the previous value. b. Extend your program to display the min and max value in the list.
Python code:
#initializing a list, num_list having 5 numbers
num_list=[2,3,4,5,6]
#print first 3 elements using slicing
print(num_list[:3])
#a)loop to change each element
for i in range(len(num_list)):
#multiplying each element by 3
num_list[i]=num_list[i]*3
#printing the new list
print(num_list)
#b)printing the minimum value in num_list
print(min(num_list))
#printing the maximum value in num_list
print(max(num_list))
Screenshot:
Output: