Python 2.7 multichoice question One effective method often used by programmers t
ID: 3838102 • Letter: P
Question
Python 2.7 multichoice question
One effective method often used by programmers to the effect of code is "tracing". Tracing is hand-executing the code in the same sequence and manner that the computer would execute the program. Often, the changes made to variables in the code are recorded in a "trace table". Each row in the trace table records the values of the variables after a corresponding statement in the left hand column of the trace table has been hand-executed. For example, for the code = 2 ford = 13 = 5 a completed trace table would be: Your task is to trace execution of the following Python code and keep track of variables alarm level and threshold: level = 10 threshold = 10 alarm = 3 if level > = threshold; if levelExplanation / Answer
You are supposed to trace the execution and to know the values of the variables.
So at first I am writing the table, then I am writing the explanation for the same...
So, let's compute the values 1 by 1 line...
in the if condition, the values are not changed, it is just doing comparison. So, the first two lines won't change the values of any variable.
The first if condition is true so it goes inside its block in which again there is an if condition.
The value of variable 'level' is 10 which is less then 100 so it is true so inside it statement gets executed.
Inside this if condition, alarm = 1 so 1, 10, 10 are the values.
And now, the next line alarm = 2 is for else condition for if level < 100. So, it is written in a way that it will get executed only when if condition is false. This is not done in this case.
So, this statement is not getting executed.
If it was getting executed, the values were 2, 10, 10 but this won't happen so I put a '-' in every values.
If there is no such option, you can consider it as that the values won't get changed in this statement as it won't get executed so after this operation also, 1, 10, 10 values will be there.
Do comment if there is any query. Thank you. :)
alarm level threshold level = 10 - 10 - threshold = 10 - 10 10 alarm = 3 3 10 10 if level >= threshold : 3 10 10 if level < 100 : 3 10 10 alarm = 1 1 10 10 alarm = 2 - - -Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.