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...
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
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...
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....
In Python syntax, create a list of 10 numbers (any numbers). Create your list 3 times,...
In Python syntax, create a list of 10 numbers (any numbers). Create your list 3 times, each time using a different syntax to define the list. Write a while loop that prints the numbers from 1 to 10. Convert your previous loop into a for loop. Rewrite your for loop to only have one number in the range. Write a for loop to print out each item of your list of 10 numbers, all on the same line, separated by...
X 1 3 5 3 4 4 Y 2 5 4 3 4 6 A: Plot...
X 1 3 5 3 4 4 Y 2 5 4 3 4 6 A: Plot the date B: find the line of best fit C: determine ŷ AT x=3 D: Find r and r^2 E: explain r and r^2
Using the Python program: a/ Write a program that adds all numbers from 1 to 100...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100 to a list (in order). Then remove the multiples of 3 from the list. Print the remaining values. b/ Write a program that initializes a list with ten random integers from 1 to 100. Then remove the multiples of 3 and 5 from the list. Print the remaining values. Please show your work and explain. Thanks
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT