3. Write a python program to input a number as keys in dictionary, therefore generate the key number starting from 1 until the "input number" with dictionary values of multiplication of two same key is provided in the following output. Note that the for loop is expected to be used for this exercise.
The output is:
Example 1:
Please input a lucky number: 8
Expected Answer:
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}
Example 2:
Please input a lucky number: 6
Expected Answer:
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36}
Sample Answer:
input_n=int(input("Please input a lucky number: ")) empty_d = dict() for i in range(1,input_n+1): empty_d[i]=i*i print(empty_d)
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)