ICT - Python Q and A
ICT - Python Q and A
Python's syntax is designed to be clear and concise, resembling English, which makes it
beginner-friendly.
Interpreted Language:
Python code is executed line by line, without the need for explicit compilation. This speeds up
development and debugging.
Dynamically Typed:
You don't need to declare variable types explicitly. Python infers them at runtime, providing
flexibility.
High-Level Language:
Python abstracts away low-level details, allowing developers to focus on problem-solving rather
than memory management.
Object-Oriented:
Python supports object-oriented programming (OOP), enabling the creation of modular and
reusable code.
Python is freely available and open-source, fostering a large and active community.
Python comes with a rich set of built-in modules and functions, providing ready-made solutions
for various tasks.
Cross-Platform Compatibility:
Python runs seamlessly on various operating systems, including Windows, macOS, and Linux.
1. Basic Input/Output:
3. Mathematical Functions:
4. Sequence Operations:
Q3. What are control statements and discussions two types of control functions
in Python?
Ans. Control statements are used to control the flow of execution of the program based Upon
some conditions values and logic.
2. Iteration statements (loops) : These statements are used for executing statements
repeatedly for a finite number of times based upon a condition.
Initialization
While <condition>:
loop body
Updation
e.g
i=1
sum = 0
While (i<=10)
sum = sum + i
print (i)
i=i+1
Ans.
if number > 0:
print("That's a positive number!")
elif number < 0:
print("That's a negative number!")
else:
print("That's zero!")
Ans.
Ans.
# Loop from 1 to 10
for i in range(1, 11):
# Calculate and print each line of the table
result = number * i
print(number, "x", i, "=", result)
Content:
* .py files contain source code.
* .pyc files contain bytecode.
Readability:
* .py files are human-readable.
* .pyc files are not easily human-readable.
Purpose:
* .py files are for writing and editing Python code.
* .pyc files are for optimizing the execution of Python code.
Generation:
* .py files are created by the programmer.
* .pyc files are automatically generated by the Python interpreter.
Speed:
* .pyc files allow for faster execution, especially when importing modules.
In essence, .pyc files are a performance optimization that allows Python to run code more
efficiently.
If statement
If…else statement
Nested if statement
elif statement
Ans. Python's code is executed directly by an interpreter, line by line. It skips a separate
compilation step into machine code. The interpreter translates and runs the code as it reads it,
making development quick and flexible.
Ans. Nested if is used when we have to check whether a condition is true and elif is used when
we check the condition is false.
Ans. Yes
Q15. What are iteration statements in Python? Define each one of them?.
Ans. Iteration statements, also known as loops, allow you to repeatedly execute a block of code.
Python provides two primary iteration statements: for loops and while loops.
1. for Loop:
The for loop iterates over a sequence (like a list)
The for loop executes a block of code repeatedly until the condition is valid
2. while Loop:
With While loop we can executed a set of statements as long as condition is true.