MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

ALGORITHMS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Python identifies blocks of code by
A
BEGIN and END keywords
B
{ and }
C
aligning up the starts of lines (indentation)
D
guessing
Explanation: 

Detailed explanation-1: -To indicate a block of code in Python, you must indent each line of the block by the same amount. The two blocks of code in our example if-statement are both indented four spaces, which is a typical amount of indentation for Python.

Detailed explanation-2: -Indentation is used to delimit code blocks (rather than the curly braces that are used in Java). All lines in a block must be indented to the same position. This is because a change in the indentation indicates the end of a code block.

Detailed explanation-3: -A block is a piece of Python program text that is executed as a unit. The following are blocks: a module, a function body, and a class definition. Each command typed interactively is a block.

Detailed explanation-4: -Not only does Python require this indentation so that it can recognize the code blocks, but the consistent indentation makes it easy for people to recognize the if/elif-conditions and their corresponding code blocks. As with a regular if-statement, the else-block is optional.

There is 1 question to complete.