Question
Matching numbers to squares: PYTHON Coding Please write a function called matchNumbers that accepts a single argument: an integer value. Your function should build a
Matching numbers to squares: PYTHON Coding
Please write a function called matchNumbers that accepts a single argument: an integer value. Your function should build a dictionary that contains the same number of keys as indicated by the argument. The keys should start at 1 and increment up to (and including) the value of the argument. The value corresponding to each key should be the square of the key. For example, if this function were invoked as below:
matchNumbersToSquares(3)
Your function would return the following dictionary:
{1: 1, 2: 4, 3: 9}
Test code (to be executed after your solution):
# Generate test results resultA = matchNumbers(3) resultB = matchNumbers(5) resultC = matchNumbers(10) # Check keys and values in resultA print(0 not in resultA) print(resultA[1]) print(resultA[2]) print(resultA[3]) # Check keys and values in resultB print(resultB[1]) print(resultB[5]) # Check keys and values in resultC print(resultC[3]) print(resultC[8])
OUTPUTS:
True 1 4 9 1 25 9 64
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started