Python Programming
June 16, 2025 at 03:07 AM
Today, Let’s move on to the next topic in the Python Coding Challenge:
🔹 *Day 9: Function Arguments in Python*
🤔 *Why are Arguments Important?*
Arguments allow us to pass data into a function so it can act on different values — making the function dynamic instead of static.
✅ *Types of Function Arguments*
*1. Positional Arguments*
These are the most common — the order matters.
```def greet(name, age):
print(f"{name} is {age} years old.")
greet("Alex", 25) ```
*2. Keyword Arguments*
You specify the name of the argument, so order doesn’t matter.
greet(age=25, name="Alex")
*3. Default Arguments*
Provide a default value so the argument becomes optional.
```def greet(name, city="Delhi"):
print(f"{name} is from {city}")
greet("Riya") # Uses default city
greet("Riya", "Mumbai") # Overrides default
```
*4. Variable-length Arguments*
*args for multiple positional values (tuple)
**kwargs for multiple keyword values (dictionary)
```
def total(*numbers):
return sum(numbers)
print(total(2, 4, 6)) # Outputs: 12
def display_info(**data):
for key, value in data.items():
print(f"{key} = {value}")
display_info(name="John", age=30)
```
🔨 *Mini Project: Tip Calculator with Tax*
```
def calculate_total(bill, tip_percent=10, tax_percent=5):
tip = bill * (tip_percent / 100)
tax = bill * (tax_percent / 100)
return bill + tip + tax
amount = float(input("Enter bill amount: "))
total_amount = calculate_total(amount, tip_percent=15)
print(f"Total Amount to Pay: ₹{total_amount:.2f}")
```
🧠 This project demonstrates:
- Positional and default arguments
- Mathematical logic
- Function flexibility
*React with ❤️ once you’re ready for the quiz*
Python Coding Challenge: https://whatsapp.com/channel/0029VaiM08SDuMRaGKd9Wv0L/1661
❤️
❤
👍
🇮🇳
😂
🇵🇸
🙏
👏
💯
😢
345