Answer to Question #329090 in Python for ratul

Question #329090

Write a function called make_square that takes a tuple in the parameter as a range of numbers

(starting point and ending point (included)). The function should return a dictionary with the

numbers as keys and its squares as values.

===================================================================

Hints:

You need to declare a dictionary to store the result. You should use the range function to run

the “for loop”.

===================================================================

Example1:

Function Call:

make_square((1,3))

Output:

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

===================================================================

Example2:

Function Call:

make_square((5,9))

Output:

{5: 25, 6: 36, 7: 49, 8: 64, 9: 81}


1
Expert's answer
2022-04-19T10:02:08-0400
def make_square(my_tuple):
    list_keys = []
    for i in range(my_tuple[0], my_tuple[1]+1, 1):
        list_keys.append(i)
    d = dict.fromkeys(list_keys)
    for i in range(my_tuple[0], my_tuple[1]+1, 1):
        d[i] = i**2
    return d


print("Please enter starting point (0) -> Enter - > ending point (1)")
a = tuple([int(input(str(i) + ": ")) for i in range(2)])
print(make_square(a))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS