What are the advantages of Python?
Readability and Simplicity: Python code is easy to read and write, making it accessible for beginners and reducing the cost of program maintenance.
Versatility: Python is a versatile language that can be used for web development, data science, artificial intelligence, machine learning, automation, and more.
Large Standard Library: Python comes with a vast standard library that includes modules and packages for a wide range of tasks, eliminating the need for additional downloads.
Object-Oriented Language: Python supports both procedural and object-oriented programming, promoting code reuse and modular design.
Python is a scripting language. Comment.
Python's concise syntax, ease of use, and the ability to interact with other languages and systems make it well-suited for scripting tasks.
- What is dry run in Python?
A dry run in Python refers to the process of mentally or manually simulating the execution of code without actually running it on a computer. It helps developers understand the flow of the program, identify potential errors, and verify the logic before executing the code.
- Write a short note on datatypes in Python.
Python supports various data types, including:
Numeric Types: Integers, Floats, Complex Numbers
Sequence Types: Strings, Lists, Tuples
Mapping Type: Dictionary
Boolean Type: bool
What is the output of following code :
def f(X) :
def f1(a, b) :
print ("hello")
if (b==0) :
print ("NO")
return
return f(a, b)
return f1
@ f
def f(a, b) :
return a%b
f(4, 0)
X = 5
def f1( ):
global X
X = 4
f2(a, b) :
global X
return a+b+X
f1()
total = f2(1, 2)
print (total)
- Define identifiers.
- Write a Python program to check if a given number is Armstrong.
- Write a Python program to check for Zero Division Error Exception.
def divide_numbers(dividend, divisor):
try:
result = dividend / divisor
print(f"Result of {dividend} / {divisor} is: {result}")
except ZeroDivisionError:
print("Error: Division by zero is not allowed.")
# Example usage:
try:
dividend = float(input("Enter the dividend: "))
divisor = float(input("Enter the divisor: "))
divide_numbers(dividend, divisor)
except ValueError:
print("Error: Please enter valid numeric values.")