Menu Close

 In Form X and X*X using dictionary Python…FTC

Python Program to Generate a Dictionary that Contains Numbers (between 1 and n) in the Form (x , x*x).

INPUT
5

OUTPUT
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
N=int(input())
dict={}
for i in range(1,N+1):
    dict[i]=i**2
print(dict)


INPUT_1:
5

OUTPUT:
{1: 1,  2: 4,  3: 9,  4: 16,  5: 25}


INPUT_2:
10

OUTPUT:
{1: 1,  2: 4,  3: 9,  4: 16,  5: 25,  6: 36,  7: 49,  8: 64,  9: 81,  10: 100}


INPUT_3:
15

OUTPUT:
{1: 1,  2: 4,  3: 9,  4: 16,  5: 25,  6: 36,  7: 49,  8: 64,  9: 81,  10: 100,  11: 121,  12: 144,  13: 169,  14: 196,  15: 225}


INPUT_4:
9
OUTPUT:
{1: 1,  2: 4,  3: 9,  4: 16,  5: 25,  6: 36,  7: 49,  8: 64,  9: 81}


INPUT_5:
3

OUTPUT:
{1: 1,  2: 4,  3: 9}


ILLUSTRATION

Executed using python3