Python Preparation
Python Preparation
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
## **18. Zig-Zag Pattern**
```python
n=5
for i in range(1, n + 1):
for j in range(1, n + 1):
if (i + j) % 2 == 0:
print("*", end=" ")
else:
print(" ", end=" ")
print()
```
**Output:**
```
* * *
* *
* * *
* *
* * *
```
---
---
---
===========================================================
Here's a comprehensive collection of **100 Python programs** covering all fundamental concepts
asked in technical interviews, categorized for easy learning.
def introduce(self):
print(f"Hi, I'm {self.name}, {self.age} years old")
p = Person("Alice", 25)
p.introduce()
```
class Dog(Animal):
def speak(self):
print("Bark")
dog = Dog()
dog.speak()
```
class Airplane:
def fly(self):
print("Flying with engines")
def let_it_fly(flying_object):
flying_object.fly()
let_it_fly(Bird())
let_it_fly(Airplane())
```
def get_balance(self):
return self.__balance
account = BankAccount()
account.deposit(100)
print("Balance:", account.get_balance())
```
class Child(Parent):
def show(self):
print("Child method")
obj = Child()
obj.show()
```
try:
num = -5
if num < 0:
raise NegativeNumberError("No negative numbers")
except NegativeNumberError as e:
print(e)
```
@my_decorator
def say_hello():
print("Hello!")
say_hello()
```
def __enter__(self):
self.file = open(self.filename, 'w')
return self.file
with ManagedFile('hello.txt') as f:
f.write("Hello, world!")
```
def print_numbers():
for i in range(5):
print(i)
thread = threading.Thread(target=print_numbers)
thread.start()
thread.join()
```
arr = [1, 3, 5, 7, 9]
print("Found at index:", binary_search(arr, 5))
```
class LinkedList:
def __init__(self):
self.head = None
def print_list(self):
current = self.head
while current:
print(current.data, end=" -> ")
current = current.next
print("None")
ll = LinkedList()
ll.append(1)
ll.append(2)
ll.append(3)
ll.print_list()
```
while queue:
vertex = queue.popleft()
print(vertex, end=" ")
graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [],
'E': ['F'],
'F': []
}
print("BFS traversal:")
bfs(graph, 'A')
```
=============================================================
# **Python Array & String Based Interview Questions (100+ Problems)**
Here's a **comprehensive collection** of array and string manipulation problems frequently asked
in technical interviews, categorized by difficulty with complete solutions.
---
---
---
---
---
---
---
Here are **100 Python programs** with **direct code and output** (no functions, just
straightforward implementation). These cover **basic programs, patterns, arrays, strings, and
more** for placement preparation.
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
### **Continue with more programs? (Next: Sorting, Matrix, File Handling, OOPs, etc.)**
Let me know if you want **more programs** in any specific category! 🚀