Python 7 Marks Answers
Python 7 Marks Answers
1. Explain the history and evolution of Python, including versions and creator
information:
Python was created by Guido van Rossum in the late 1980s and released in 1991. Its
early version, Python 0.9.0, included functions, modules, and exceptions. Python
2.x (2000) introduced Unicode support and list comprehensions. Python 3.x (2008)
fixed design flaws and included better Unicode handling and syntax improvements.
Python 3.10+ includes modern features like pattern matching and performance boosts.
3. Explain the steps to install Python on Windows and configure it with VS Code or
IDLE:
- Download Python from python.org.
- Run installer and select "Add Python to PATH".
- Install VS Code from code.visualstudio.com.
- Open VS Code, install the Python extension.
- Set Python interpreter via Command Palette > "Python: Select Interpreter".
- Use IDLE directly from the Start Menu if preferred.
9. Mutable vs Immutable:
- Mutable: Can be changed (lists, dicts).
- Immutable: Cannot be changed (strings, tuples).
3. for vs while:
- for: Used with known ranges.
- while: Used with unknown conditions.
```python
for i in range(3): print(i)
i = 0
while i < 3:
print(i)
i += 1
```
4. Pattern program:
```python
for i in range(1, 4):
for j in range(1, i+1):
print(j, end=" ")
print()
```
5. Prime check:
```python
n = int(input("Enter number: "))
if n > 1:
for i in range(2, n):
if n % i == 0:
print("Not Prime")
break
else:
print("Prime")
else:
print("Not Prime")
```
# continue
for i in range(5):
if i == 3:
continue
print(i)
# pass
for i in range(5):
if i == 3:
pass
print(i)
```
7. Menu-driven program:
```python
while True:
print("1.Add 2.Subtract 3.Exit")
choice = int(input("Enter choice: "))
if choice == 3:
break
a = int(input("Enter a: "))
b = int(input("Enter b: "))
if choice == 1:
print("Sum:", a + b)
elif choice == 2:
print("Difference:", a - b)
```
9. Multiplication table:
```python
n = int(input("Enter number: "))
for i in range(1, 11):
print(f"{n} x {i} = {n*i}")
```