Dictionary-Returned Function a) Define a function, dictSqrt() with a parameter, x: 1) Create a list, num and uses a loop to store, x numbers into the list in the range of (0, x). 2) Create a list, sqrtNum and store all sqrt of the numbers saved in the list above. 3) Use dict() and zip() to create a dictionary, sqrtDict, as the return value with numbers as the keys and their corresponding sqrt as the values. b) Define a main() function to do the following: 1) Get a random integer, n, in the range (1, 10). 2) Call dictSqrt() with the argument and print the returned dictionary. c) Call main() function to initiate the tasks to be performed. Example Output dictSqrt(3)will print the following: {0:0, 1:1, 2:1} PYTHON
Dictionary-Returned Function
a) Define a function, dictSqrt() with a parameter, x:
1) Create a list, num and uses a loop to store, x numbers into the list in the range of (0, x).
2) Create a list, sqrtNum and store all sqrt of the numbers saved in the list above.
3) Use dict() and zip() to create a dictionary, sqrtDict, as the return value with numbers as the keys and their
corresponding sqrt as the values.
b) Define a main() function to do the following:
1) Get a random integer, n, in the range (1, 10).
2) Call dictSqrt() with the argument and print the returned dictionary.
c) Call main() function to initiate the tasks to be performed.
Example Output
dictSqrt(3)will print the following:
{0:0, 1:1, 2:1}
PYTHON
Step by step
Solved in 3 steps with 1 images