Question
PYTHON Print the two-dimensional list mult_table by row and column. On each line, each character is separated by a space. Hint: Use nested loops. Sample
PYTHON
Print the two-dimensional list mult_table by row and column. On each line, each character is separated by a space. Hint: Use nested loops. Sample output with input: '1 2 3,2 4 6,3 6 9':
1 | 2 | 3 2 | 4 | 6 3 | 6 | 9
user_input= input() lines = user_input.split(',')
# This line uses a construct called a list comprehension, introduced elsewhere, # to convert the input string into a two-dimensional list. # Ex: 1 2, 2 4 is converted to [ [1, 2], [2, 4] ]
mult_table = [[int(num) for num in line.split()] for line in lines]
''' Your solution goes here ''' for lst in mult_table: for i in range(len(lst)): print(lst[i], end='') if i != len(lst)-1: print(' | ',end='') print()
testing with input: '1 2 3,2 4 6,3 6 9'
Output is nearly correct; but whitespace differs. See highlights below. Special character legend
Your output
1 | 2 | 32 | 4 | 63 | 6 | 9
Expected output
1 | 2 | 3 2 | 4 | 6 3 | 6 | 9
clearTesting with input: '1 2 3 4,2 4 6 8,3 6 9 12,4 8 12 16'
Output is nearly correct; but whitespace differs. See highlights below. Special character legend
Your output
1 | 2 | 3 | 42 | 4 | 6 | 83 | 6 | 9 | 124 | 8 | 12 | 16
Expected output
1 | 2 | 3 | 4 2 | 4 | 6 | 8 3 | 6 | 9 | 12 4 | 8 | 12 | 16
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started