• 如果您觉得本站非常有看点，那么赶紧使用Ctrl+D 收藏吧

# Python code question 7

2周前 (01-11) 12次浏览

### Question 7

Level 2

Question: Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. The element value in the i-th row and j-th column of the array should be i*j. Note: i=0,1.., X-1; j=0,1,¡­Y-1. Example Suppose the following inputs are given to the program: 3,5 Then, the output of the program should be: [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]

Hints: Note: In case of input data being supplied to the question, it should be assumed to be a console input in a comma-separated form.

Solution:

``````#!/usr/bin/env python
# encoding: utf-8
'''
@author: developer
@contact:
@software:
@file: q7.py
@time: 2021/1/11 10:45 上午
@desc:
'''

'''
Question: Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional
array.
The element value in the i-th row and j-th column of the array should be i*j.
Note: i=0,1.., X-1; j=0,1,¡­Y-1. Example Suppose the following inputs are given to
the program: 3,5 Then,
the output of the program should be: [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]

Hints: Note: In case of input data being supplied to the question,
it should be assumed to be a console input in a comma-separated form.

'''

line_row = [x for x in input("Please input two numbers:").split(',')]
line = int(line_row)
row = int(line_row)
temp = []

for i in range(line):
temp.append(*row)

for i in range(line):
for j in range(row):
temp[i][j] = i*j

print(temp)

``````

{{o.name}}

{{m.name}}