Unit-5 Intro to Python
ASSIGNMENT
OBJECTIVE TYPE QUESTIONS
A. Choose the correct answer
1. a. Integrated Development and Learning 13. c. PythonPython Language
Environment 14. c. Modules (spell mistake, it is "Modulus")
2. a. .py 15. a. Indentation
3. c. Script mode 16. b. if a>-2:
4. a. age_entry 17. d. for
5. a. int 18. c. 55 53 51
6. c. // 19. b. float
7. c. "\t" 20. d. elif
8. b. string 21. --- not in HY
9. b. float() 22. --- not in HY
10. d. None of these (output will be 5 5) 23. a. range()
11. c. Decimal 24. --- not in HY
12. d. list 25. --- not in HY
B. Fill in the blanks
1. algorithm 8. statement 15. Dictionary
2. flowchart 9. Multi-line comment 16. operands
3. interactive and script 10. Keywords 17. assignment (=)
4. variable 11. Identifier 18. escape sequences
5. Data Type conversion 12. Constants 19. Implicit type conversion
6. Comments 13. list 20. break and continue
7. decision 14. string
C. True/ False
1. T 6. F 11. T
2. T 7. F 12. T
3. T 8. T 13. T
4. F 9. F 14. F
5. F (It is >>>) 10. T 15. T
Subjective Type Questions
Short Answer Type Questions
1. What is an algorithm?
• Algorithm is a set of finite rules or instructions to be followed in calculations or other problem solving
operations.
• It is a procedure for solving a mathematical problem in a finite number of steps that frequently involves
recursive operations.
• Algorithms can be presented by any natural languages.
2. What is a flowchart?
• A flowchart is the graphical or pictorial representation of an algorithm with the help of different symbols,
shapes and arrows in order to demonstrate a process or a program.
• Flowcharts are used to break a process into smaller parts and elaborate it using visual representations.
• It represents different types of actions or decisions and shows the flow of control from one step to the
next.
4. --- on in HY
3. List all the standard graphics for making a flowchart.
Standard flowchart symbols include:
5. What is an infinite loop?
In case of a while loop in python, when the condition provided never becomes False then the loop will never
end and it continues to execute indefinitely.
Example:
while True:
print("This will print forever")
6. Write the difference between the 'else' and 'elif' statements.
Elif else
It requires a condition It cannot have a condition
It is used to give alternative condition to if Used when none of the above conditions
condition provide in if and elif are True
We can have only one else in a selection
We can have multiple elifs in a selection block
block
7. What are nested loops?
A nested loop is a loop inside another loop. The inner loop runs completely every time the outer loop runs once.
Example:
for i in range(1, 4): # Outer loop (for each row)
for j in range(1, i + 1): # Inner loop (for each element in the row)
print(j, end=" ")
print()
Long Answer Type Questions
1. Algorithm to Display How a Traffic Signal Works
Algorithm:
1. Start
2. Display "Red Light"
3. Wait for 60 seconds
4. Display "Yellow Light"
5. Wait for 5 seconds
6. Display "Green Light"
7. Wait for 60 seconds
8. Repeat from Step 2
2. Explain ‘if-else’ Statement with a Flowchart
Explanation:
if...else statement is a control statement that helps in decision-making based on specific conditions. When the
if condition is False. If the condition in the if statement is not true, the else block will be executed.
Flowchart of if-else:
3. Difference Between Division and Floor Division Operators
Operator Symbol Description Example Result
Division / Returns float result 7/2 3.5
Floor/ Integer Returns integer part of the division (floor/
// 7 // 2 3
Division round off value)
4. Use of input() and print() Functions
• input(): It is used to take input from the user. It returns the input as a string.
o Example: name = input("Enter your name: ")
• print(): It is used to display output on the screen.
o Example: print("Hello", name)
5. Difference Between ‘for’ Loop and ‘while’ Loop (with Flowchart)
for loop while loop
Iterates over a sequence or a range Repeats until a condition is true
It is used when the statements are repeated based
It is used for a fixed number of iterations
on a condition
Example, for i in range(5): Example, while i<=5:
Flowchart for for loop:
Flowchart for while loop:
6. What are Python Nested-If Statements? (With Example)
Explanation:
Nested if...else statement occurs when if...else structure is placed inside another if or else block. Nested If..else
allows the execution of specific code blocks based on a series of conditional checks
Example:
num = float(input("Enter a number: "))
if num >= 0:
if num == 0: #nested if
print("Zero")
else:
print("Positive number")
else:
print("Negative number")
7. --- not in HY
8. What is Typecasting? Explain Its Types
The process of converting the value of one data type (integer, string, float, etc.) to another data type is called
typecasting or type conversion.
Python has two types of type conversion.
1. Implicit Typecasting: In Implicit type conversion of data types in Python, the Python interpreter
automatically converts one data type to another without any user involvement. Example:
x=5
y = 2.5
result = x + y
# result will be 7.5, a float value, as the integer x is converted automatically
2. Explicit Typecasting: In Explicit Type Conversion in Python, the data type is manually changed by the user as
per their requirement. We use the predefined functions like int(), float(), str(), etc to perform explicit type
conversion.
Example:
a = "10"
b = int(a) # Convert string to integer
print(b + 5) # Output will be 15, an integer value