Question: Write a function called compare _ numbers. It should have the following: 2 inputs which are called num _ 1 and num _ 2 in

Write a function called compare_numbers. It should have the following:
2 inputs which are called num_1 and num_2 in that order
an output called info
has a nested function called comparison. This nested function should have the following:
2 inputs which are called first_num and second_num in that order
an output called comp_result
If first_num is bigger than second_num, set comp_result to 1
Otherwise, set comp_result to 0
End of comparison function instructions
One good use of a Nested function is if we have a piece of code that we want to repeat various times across a function. Lets look at an example of that:
Write a function called compare_numbers. It should have the following:
2 inputs which are called num_1 and num_2 in that order
an output called info
has a nested function called comparison. This nested function should have the following:
2 inputs which are called first_num and second_num in that order
an output called comp_result
If first_num is bigger than second_num, set comp_result to 1
Otherwise, set comp_result to 0
End of comparison function instructions
Using the function called comparison, compare num_1 and num_2, with num_1 being the first_num.
Assign the result to a variable called fish
Using the function called comparison for a second time, compare num_1 to 10, num_1 being the first_num.
Assign the result to a variable called cat
calculate the sum of fish and cat. Assign this result to info

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 Programming Questions!