Suppose that one day you and a group of friends decide to come up with a brand new programming language, with syntax similar to Java's. After it is finished you decide to test it out with a program that prints two integers on the same line as shown below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
You and your friends still have not yet agreed on whether the programming language should follow either static scoping or dynamic scoping.
If if follows static scoping it will print out
1 |
|
where and are integers.
If it follows dynamic scoping, it will print out
1 |
|
where and are integers.
Find the value of
The prime factors of a number are all the prime numbers that divide it. For example the prime factors of are 13, 31, and 5 (). The following Python function finds the largest prime factor of a number.
1 2 3 4 5 6 7 8 9 10 |
|
The program works well for most inputs but it contains a variable whose scope is not properly defined. Identify the variable.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Consider the above algorithm, in c++ the notation is used to refer back to the the variable defined in the global namespace. Let and be the output results of line , and , respectively then what is the value of
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Consider the fragment of theoretical python code. Predict what will be outputted when it is run once.
Side note: This is an example of very poor function and variable naming. Proper naming in programming is one of the keys to writing good code.