Using Python programming, create a 2-by-3 list, then use a nested loop to:
1) Set each element's value to an integer indicating the order
in which it was processed by the nested loop (1, 2, 3, 4, 5,
6).
2) Display the elements in tabular format. Use the column indices
as headings across the top, and the row indices to the left of each
row.
Code:
lst=[] #main list declaration
count=1 #take count variable for assigning valeus
for i in range (2): #2*3 list means two rows and 3 columns so
iterate outer loop 2 times
temp=[] #take temporary list
for j in range (3): #iterate inner loop three times for 3
columns
temp.append(count) #append count value to temp list
count=count+1 #increment the count value
lst.append(temp) #append the temp list to main list
print(" ",end=" ") #print for alignment
for i in range(3): #print column indices
print(i,end=" ")
print("\n-------")
for i in range(2): #iterate loop
print(i,end="|") #print row indices
for j in range(3): #iterate loop for column value
print(lst[i][j], end = " ") #print column value
print() #print new line
Code and Outputs Screenshots:
Note: The tabular format is designed in the best possible way . if we want perfect table format we need to use numpy arrays.
Note : if you have any queries please post a comment thanks a lot..always available to help you..
Using Python programming, create a 2-by-3 list, then use a nested loop to: 1) Set each...
Create a square array and fill out as shown below. Use a nested loop for this step. 1 3 5 7 9 2 4 6 8 10 3 5 7 9 11 4 6 8 10 12 5 7 9 11 13 Then create two 1D arrays to with row and column sum of the items. You have then 15 25 35 45 55 for the column sum, and 25 30 35 40 45 for the row sum. Print row...
3) Top-selling products (30 points) Use Python programming to find most popular single products and co-purchased products from the large transaction data: retail.csv. Each row in the file is one purchase transaction from a customer, including a set of product ids separated by commas. The first column is transaction ID, column 2-3 are the products ID purchased in this transaction. It is worth mentioning that if the value in third column is zero, it means this customer only purchased one...
Create a square array and fill out as shown below. Use nested loop for this step. 1 3 5 7 9 2 4 6 8 10 3 5 7 9 11 4 6 8 10 12 5 7 9 11 13 Then create two 1D arrays to with row and column sum of the items. You have then 15 25 35 45 55 for the column sum, and 25 30 35 40 45 for the row sum. Print row and...
IN PYTHON Problem 2: (20pt) Use nested list to create a grid as follows, 100001 100001 100001 011110 011110 011110
Using Python, Can someone please assist in the following: These are the hints: Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to display a warning if the number is less than 2 or greater than 10 and prompt the user to enter the data again until they enter a valid number Put a...
PYTHON PROGRAMMING LANGUAGE Task 5 Open a csv file for writing create 3 rows that store username, first name, last name and age data (four columns) write the data to the csv file under the correct column Task 6 Open the file in task 5) and read its contents Output the content in a tabular format of columns and values
Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python statement that creates a two-dimensional list named values with 3 rows and 2 columns. Then write nested loops that get an integer value from the user for each element in the list. Then display the content of the list. Please see the outcome below: Outcome run: Enter the 1 element in the 1 row :1 Enter the 2 element in the 1 row :2...
Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python statement that creates a two-dimensional list named values with 3 rows and 2 columns. Then write nested loops that get an integer value from the user for each element in the list. Then display the content of the list. Please see the outcome below: Outcome run: Enter the 1 element in the 1 row :1 Enter the 2 element in the 1 row :2...
How can I following questions by using nested for loop in Python 3? Q1. ----1 ---2- --3-- -4--- 5---- Q2 -----1----- ----333---- ---55555--- --7777777-- -999999999-
PYTHON Ask the user for an integer number n. Construct, using one single loop, the list with the values [1,2,3,4,…,n] and the list with the values [1^2 ,2^2 ,3^2 ,…n^2 ] by using list concatenation ). After this loop is over, use a separate loop to show the user the two results by printing corresponding elements from the two lists in the same line, as follows: 1 1 2 4 3 9 … …