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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!