Write a function that prints a dictionary where the keys are numbers between 1 and 5 and the values are cubes of the keys.

by

Last updated on Nov 5, 2022
Python Practicals (Question 11)

Input

def dict_cube():
    values = {'1': '', '2': '', '3': '', '4': '', '5': '', }
    for i in values.keys():
        values.update({i: (int(i) ** 3)})
    return values


print(dict_cube())

Output

{'1': 1, '2': 8, '3': 27, '4': 64, '5': 125}

How useful was this post?

5 star mean very useful & 1 star means not useful at all.

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Tags: