All_Simple_Python_Programs
All_Simple_Python_Programs
Key Points: We use `if-elif-else` to check the price range and apply tax accordingly. Simple comparison logic.
Key Points: `lambda` creates tiny functions without using `def`. `map` applies that function to each item of list.
Simple and clean.
Key Points: `try-except` handles errors like wrong input or divide by zero. Menu runs in loop till user exits.
Key Points: Functions make code reusable. We pass values to calculate area and perimeter separately.
total = sum(marks)
percentage = total / 5
Key Points: We use a loop to collect marks, then `sum()` to get total and calculate percentage easily.
def getArea(self):
return self.length * self.breadth
obj = Area()
l = int(input("Enter length: "))
b = int(input("Enter breadth: "))
obj.setDim(l, b)
print("Area:", obj.getArea())
Key Points: Using class to hold dimensions and return area. Easy OOP example with method calling.
8. Map Two Lists into Dictionary
colors = ['red', 'blue']
codes = ['#ff0000', '#00ff00']
Key Points: `zip()` combines two lists. `dict()` turns them into a dictionary directly.
Key Points: `in` keyword checks if element exists inside tuple. Simple and fast.