In: Computer Science
import sys
var = 1
print(var)
def function1(myVar):
print(myVar)
var = myVar + 1
print(var)
function2(var)
def function2(myVar):
print(myVar)
var = myVar + 1
print(var)
function3(var)
def function3(myVar):
print(myVar)
var = myVar + 1
print(var)
def main(argv):
var = 10
print(var)
function1(var)
if __name__=="__main__":
main(sys.argv)
1. As the program runs, what is the first line that will be interpreted by Python, and what action will be executed?
2. What will be printed on line 7?
3. What will be printed on line 9?
4. What will be printed on line 13?
5. What will be printed on line 15?
6. What will be printed on line 19?
7. What will be printed on line 21?
8. What will be printed on line 25?
9. What is the scope of the variable at line 3?
10. What will happen if a command line argument other than the script name is passed to this program?
For the above questions, below answer may help you
1. As the program runs, what is the first line that will be
interpreted by Python, and what action will be executed?
Answer: import sys
2. What will be printed on line 7?
Answer: print(myVar) result = 10
3. What will be printed on line 9?
Answer: print(var) result = 11
4. What will be printed on line 13?
Answer: print(myVar) result = 11
5. What will be printed on line 15?
Answer: print(var) result = 12
6. What will be printed on line 19?
Answer: print(myVar) result = 12
7. What will be printed on line 21?
Answer: print(var) result = 13
8. What will be printed on line 25?
Answer: print(var) result = 10
9. What is the scope of the variable at line 3?
Answer: Local variable
10. What will happen if a command line argument other than the
script name is passed to this program?
Answer: start the execution from main method
if you want track other program in python
python -m trace --ignore-dir=../lib --trace <program_name>.py