1. What is Python? List some features of Python.
Python is a high-level, interpreted programming language known for its simplicity and readability.
Features:
- Easy to learn and use
- Interpreted language
- Dynamically typed
- Object-oriented
- Large standard library
- Open-source and community-developed
2. List any five applications of Python.
1. Web Development
2. Data Science and Machine Learning
3. Automation/Scripting
4. Game Development
5. Desktop GUI Applications
3. Explain how Python is interpreted.
Python code is executed line-by-line using an interpreter. It converts source code into bytecode and
then executes it using the Python Virtual Machine (PVM).
4. Define tokens. List different types of tokens in Python.
Tokens are the smallest units of a Python program.
Types:
- Keywords
- Identifiers
- Literals
- Operators
- Punctuators (delimiters)
5. Write a Python program to print 'Python is easy'.
print("Python is easy")
6. Write a Python program to perform the arithmetic operations.
a = 10
b=5
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
7. Write a Python program to find the area of a circle.
r = float(input("Enter radius: "))
area = 3.14159 * r * r
print("Area of circle:", area)
8. Write a Python program to swap two numbers.
a=5
b = 10
a, b = b, a
print("a:", a, "b:", b)
9. Write a Python program to find the square and cube of a number.
num = int(input("Enter a number: "))
print("Square:", num**2)
print("Cube:", num**3)
10. Explain variables and data types in Python.
Variables are containers for storing data values.
Data Types:
- int (e.g., 10)
- float (e.g., 10.5)
- str (e.g., 'hello')
- bool (True/False)
- complex (e.g., 3+4j)
11. Explain the if-elif-else ladder with an example.
num = int(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
12. Write a Python program to check whether a number is even or odd.
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
13. Write a Python program to check whether a number is positive, negative, or zero.
num = int(input("Enter a number: "))
if num > 0:
print("Positive")
elif num == 0:
print("Zero")
else:
print("Negative")
14. Write a Python program to check if a year is a leap year.
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap year")
else:
print("Not a leap year")
15. Write a Python program to find the largest of three numbers.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a >= b and a >= c:
print("Largest:", a)
elif b >= a and b >= c:
print("Largest:", b)
else:
print("Largest:", c)
16. Explain while loop with an example.
i=1
while i <= 5:
print(i)
i += 1
17. Write a Python program to print numbers from 1 to 10 using while loop.
i=1
while i <= 10:
print(i)
i += 1
18. Write a Python program to print even numbers between 1 and 20 using while loop.
i=2
while i <= 20:
print(i)
i += 2
19. Write a Python program to display the multiplication table of a number.
num = int(input("Enter a number: "))
i=1
while i <= 10:
print(f"{num} x {i} = {num*i}")
i += 1
20. Write a Python program to print factorial of a number using while loop.
num = int(input("Enter a number: "))
fact = 1
i=1
while i <= num:
fact *= i
i += 1
print("Factorial:", fact)