Chapter 7 Review Python
Brain Developers
A. Fill in the blanks:
1. The data type of a variable is an attribute that tells what kind of data can a variable have.
2. There are two types of string operators.
3. The statements that govern the flow of a program are called control statement.
4. Comments are the statements that are written while programming but are not executed during program execution.
5. F5 is the shortcut key to execute a program.
B. State True or False:
1. Logical operators are used to assign a value to the variable. (False)
Correct Answer: Assignment operators are used to assign a value to the variable.
2. The value of the variable cannot be changed during program execution. (False)
Correct Answer: The value of the variable may or may not be changed during program execution.
3. In Python, ‘and’ is an example of Logical operators. (True)
4. Script Mode is used to create files in Python. (True)
5. Python is a case-sensitive language. (True)
C. Multiple Choice Questions:
1. Python can work in _____________ different modes.
a) Three
b) Four
c) Two
d) Five
Answer: c) Two
2. Concatenation is a ___________ operator.
a) String
b) Integer
c) Float
d) Boolean
Answer: a) String
3. A single line comment can be created by using the _________ symbol.
a) $
b) #
c) &
d) @
Answer: b) #
4. The ___________ construct executes the statements in a sequential manner.
a) Iterative
b) Conditional
c) Selection
d) Sequential
Answer: d) Sequential
5. The files in Python are saved with the extension ________.
a) .pyth
b) .py
c) .pthy
d) .python
Answer: b) .py
D. Answer the following:
1. Write any two features of Python that make it user-friendly.
Answer: Two features of Python that make it user-friendly are
• Simple and interactive
• Platform independent
2. What is the difference between the Interactive mode and the Script mode of Python.
Answer: In the Interactive mode, Python displays the results of expression. In the Script mode, Python does not automatically display results. Interactive mode is used to write small programs because the output in the Interactive mode is compressed between the statements and is not suitable for writing lengthy programs. So, to write lengthy programs we use the Script mode in which we can create and edit the programs. The files created in the Script mode can be saved for later use.
3. What is the purpose of adding a comment in the program? What are the two ways used to add the comments in Python?
Answer: Comments are the statements that are added to a program with the purpose of making the code easier to understand. There are two types of comments in Python:
• Single Line comments
• Multiline comments
4. How is ‘if’ statement different from ‘if…else’ statement?
Answer:
‘if’ statement: This statement is used to evaluate only one condition. It performs a course of action if the condition evaluates to true, otherwise it skips the statements.
‘if…else’ statement: This statement is used when either of two different actions are to be performed depending the result of the conditional expression. It works on two blocks: if and else. In case the conditional expression evaluates to true, the statements in the ‘if’ block are executed, and if the statement is false, then the statements in the ‘else’ block are executed.
5. Differentiate between the function of ‘+’ operator when used with integer and string values.
Answer: If ‘+’ operator is used with integer values, it is used to find the sum of the data values. But if ‘+’ operator is used with string values, it is used to join two string values.
6. What is the difference between the following statement?
a=10 and a==10
Answer: In the statement a=10, the variable ‘a’ is assigned value 10. However, in the statement a==10, the value of ‘a’ is equated with 10. The ‘=’ (equal to) sign is the assignment operator in Python, whereas, ‘==’ sign is called the equal to operator.
No comments:
Post a Comment