Question: Python A simple definition of scope is: 'Scope is the set of program instructions over which a variable exists, i.e. can be referred to.' 1.

Python

A simple definition of scope is: 'Scope is the set of program instructions over which a variable exists, i.e. can be referred to.'

1. Write a function named getValue, that will get an integer value from the user and save it in a variable called number. Then your function should use number to output the value.

2. Use the following main function print number. You will get an error. What causes this error? How does scope apply to this situation?

def main ():

print (number)

main()

3. Rewrite getValue() and main() so that it the value of number is accessible in main.

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!