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}
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))
Comments
Leave a comment