Q1. Five statements about interpreters & compilers are given below. Study each statement
and determine which of then hold true for a compiler or for an interpreter. 3
i. Takes one statement at a time and executes it.
ii. Generates an error report at the end of translation of the whole program.
iii. Stops the translation process as soon as the first error is encountered.
iv. Slows speed of execution of program loops.
v. Translates the entire program in one go.
Q2. ‘Python is an interpreted and high level language’. What does it mean to you? 3
Q3. What is the meaning of the term volatile primary memory? What can be done to
overcome the problems of volatility? 3
Q4. Which of the following are syntactically correct strings? State reasons. 3
i. “This course is great!”
ii. ‘She shouted “Hello!” very loudly. ’
iii. “Goodbye’
iv. ‘This course is great!’
v. “Hello
vi. “I like subject ‘Informatics Practices’ very much.”
Q5. What will be the output produced by the following code segments? 3
a. X=10 b. x,y=7,2
X=X+10 x,y,x=x+1,y+3,x+10
X=X-5 print(x,y)
print(X)
X,Y=X-2,22
print(X,Y)
Section B [5*5=25]
Q6. What will be the output of following code? Explain reasons behind output of every line:
5<5 or 10 5
5<10 or 5
5< (10 or 5)
5< (5 or 10)
(87// int (5.0))==(87//5.0)
Answers
Q1. Five statements about interpreters & compilers are given below. Study each statement and determine which of them hold true for a compiler or for an interpreter.
i. Takes one statement at a time and executes it. - Interpreter
ii. Generates an error report at the end of the translation of the whole program. - Compiler
iii. Stops the translation process as soon as the first error is encountered. - Interpreter
iv. Slows speed of execution of program loops. Interpreter
v. Translates the entire program in one go. - Compiler
Q2. ‘Python is an interpreted and high-level language’. What does it mean to you?
In python language, the execution takes place with one statement at a time. This is due to the interpreter it has. So, Python is an interpreted language.
As, python is a human-understandable language that contains symbolic representations such as identifiers, keywords, etc. Python is a high-level language.
Q3. What is the meaning of the term volatile primary memory? What can be done, to overcome the problems of volatility?
Volatile memory is nothing but temporary memory. i.e., the system can manage the data until it is powered. Once it is switched off, all the memory that is stored in the primary storage will be erased.
To avoid this, we can store the data in secondary storage devices like floppy disks, hard disks, pen drives, etc that acts as permanent storage.
Q4. Which of the following are syntactically correct strings? State reasons.
i. “This course is great!” - Correct. As the strings can be enclosed between ' ' or " ".
ii. ‘She shouted “Hello!” very loudly.’ - Correct. As, when there are some internal quotes in a string, they need to be represented with other sets of quotes.
iii. “Goodbye’ - Correct. As the strings can be enclosed between ' ' or " ".
iv. ‘This course is great!’ - Wrong. As, we need to use either ' ' or " ", but not the combination of two as in ' " or " '. Syntax error! End of line!
v. “Hello - Wrong. As there is no closing of the quotation. Syntax error!
vi. “I like subject ‘Informatics Practices’ very much.” - Correct. As, when there are some internal quotes in a string, they need to be represented with other sets of quotes.
Q5. What will be the output produced by the following code segments?
X=10
x,y=7,2
X=X+10
x,y,x=x+1,y+3,x+10
X=X-5 print(x,y)
print(X)
X,Y=X-2,22
print(X,Y)
Output:
17 5
15
13 22
Q6. What will be the output of the following code? Explain the reasons behind the output of every line:
5<5 or 10 5 - Invalid Syntax. As, 5 is another number that is syntactically wrong, as it is written immediately to the condition.
5<10 or 5 - True. As 10 is clearly greater than 5, the print statement returns True, without checking the post or statement.
5< (10 or 5) - True. Coming to or operation between two numbers, the interpreter considers the leftmost number among the two. So, it takes in 10 ignoring 5. Now, 5<10 results True.
5< (5 or 10) - False. Same as the above reason. Here, the leftmost value in or condition is 5 (ignores 10). So, 5<5 results False.
(87// int (5.0))==(87//5.0) - True. In python, 7 and 7.0 are equal. Here, int(5.0) results 5. So, 87//5 results 17 in LHS. And, 87//5.0 results 17.0 in RHS. 17 == 17.0 gives True.
Learn more:
1) Printing all the palindromes formed by a palindrome word.
brainly.in/question/19151384
2) Indentation is must in python. Know more about it at :
brainly.in/question/17731168
Answer:
Slows speed of execution of program loops.