xonecas.io
387
Pe

python-exercices / files

python-exercices / level_two / ex_7.py

869 bytes
1#!/usr/bin/env python3
2
3# Question 7
4# Level 2
5
6# Question:
7# Write a program which takes 2 digits, X,Y as input and generates a
8# 2-dimensional array. The element value in the i-th row and j-th column of
9# the array should be i*j.
10# Note: i=0,1.., X-1; j=0,1,¡­Y-1.
11# Example
12# Suppose the following inputs are given to the program:
13# 3,5
14# Then, the output of the program should be:
15# [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]]
16
17# Hints:
18# Note: In case of input data being supplied to the question, it should be
19# assumed to be a console input in a comma-separated form.
20
21x_and_y = input('\n\nEnter two numbers in the format of "X,Y"\n')
22x_and_y_split = x_and_y.split(',')
23X = int(x_and_y_split[0])
24Y = int(x_and_y_split[1])
25
26
27result = []
28for i in range(0, X):
29    result.append([])
30    for j in range(0, Y):
31        result[i].append(i*j)
32
33
34print(result)