Question

Using Python programming, create a 2-by-3 list, then use a nested loop to: 1) Set each...

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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..

Add a comment
Know the answer?
Add Answer to:
Using Python programming, create a 2-by-3 list, then use a nested loop to: 1) Set each...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT