Menu Close

 Dynamic Dictionaries Python…FTC

Write a program to print all the squares of the range from 1 to n.

Input:
Get the Value

Output:
Display the square value of the dictionary

INPUT
5

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


INPUT_1:
Value:  5

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


INPUT_2:
Value:  6

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


INPUT_3:
Value:  8

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


INPUT_4:
Value:  9

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


INPUT_5:
Value:  10

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


ILLUSTRATION

Executed using python 3 Linux terminal