Question

In: Computer Science

Write a Python program that has a list of 5 numbers [2, 3, 4, 5, 6)....

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.

Solutions

Expert Solution

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:


Related Solutions

Write a Python program that calls a function to sum all the numbers in a list...
Write a Python program that calls a function to sum all the numbers in a list and returns the result to the caller. The main program creates a list (with hard-coded or user input) and passes the list as an argument to the function. You may not use the built-in function, sum. The program calls a second function to multiply all the numbers in a list passed to it by main and returns the product back to the caller. List...
[4 5 5 2 4 4 6 3 3 7 5 3 6 3 4 4...
[4 5 5 2 4 4 6 3 3 7 5 3 6 3 4 4 6 5 4 5 3 7 5 5 4 2 6 5 6 6] This is my dataset Find mean, median, mode, variance, standard deviation, coefficient of variation, range, 70th percentile, 3rdquartile of the data and skewness and define what each of these statistics measure. For example, mean is a measure of the central tendency, what about the rest? Use Chebyshev’s rule to find...
[4 5 5 2 4 4 6 3 3 7 5 3 6 3 4 4...
[4 5 5 2 4 4 6 3 3 7 5 3 6 3 4 4 6 5 4 5 3 7 5 5 4 2 6 5 6 6] This is my dataset Split the dataset in two equal parts. You have 30 datavalues. If you split the data in two equal parts each part will contain 15 data values.  Call the first part Y and second part X.Draw scatter plot of the 2 datasets, X being on the horizontal...
Given a list x = [2,3,5,6,7,8,9], write a python program that find those numbers which are...
Given a list x = [2,3,5,6,7,8,9], write a python program that find those numbers which are divisible by 3. Arrange these numbers in a list called “result”. Hint: similar to page 9 in the slides.
Consider the matrix list x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]. Write...
Consider the matrix list x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]. Write a list comprehension to extract the first column of the matrix [1, 4, 7]. Write another list comprehension to create a vector of twice the square of the middle column.
Write a program in python language, which accepts 2 numbers and a + sign (for addition)...
Write a program in python language, which accepts 2 numbers and a + sign (for addition) A sign - (for subtraction) A sign * (for multiplication), / (for division) Then calculate and to display the result of the operation he chose with the two numbers. Displaying the appropriate message
4. Write a multithreaded program that calculates various statistical values for a list of numbers. This...
4. Write a multithreaded program that calculates various statistical values for a list of numbers. This program will be passed a series of numbers on the command line and will then create five separate worker threads. One thread will determine the average of the numbers, the second will determine the maximum value, the third will determine the minimum value, fourth will determine the median value and the fifth will compute the std. deviation. For example, suppose your program is passed...
Consider the following set of numbers: {3, 5, 2, 5, 5, 15, 2, 2, 4, 4,...
Consider the following set of numbers: {3, 5, 2, 5, 5, 15, 2, 2, 4, 4, 20, 4998, 4} 14. The Q3 of this set is: a. 4 b. 5 c. 2 d. 10 15. The Q1 of this set is: a. 4 b. 5 c. 2 d. 2.5 e. 3
ID X Y 1 2 3 2 3 6 3 4 6 4 5 7 5...
ID X Y 1 2 3 2 3 6 3 4 6 4 5 7 5 8 7 6 5 7 7 6 7 8 8 8 9 7 8 10 12 11 Test the significance of the correlation coefficient. Then use math test scores (X) to predict physics test scores (Y).  Do the following: Create a scatterplot of X and Y. Write the regression equation and interpret the regression coefficients (i.e., intercept and slope). Predict the physics score for each....
Write a program in python such that There exists a list of emails List Ls =...
Write a program in python such that There exists a list of emails List Ls = ['[email protected]','[email protected]','[email protected]','[email protected]',[email protected]'] Count the number of emails IDS which ends in "ac.in" Write proper program with proper function accepting the argument list of emails and function should print the number of email IDs and also the email IDS ending with ac.in output 2 [email protected] [email protected] ================================= i am trying like this but getting confused len [True for x in Ls if x.endswith('.ac.in')] please write complete...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT