
![]() |
@wtf | |
Tip calculator with custom tips |
||
1
Replies
7
Views
1 Bookmarks
|
![]() |
@wtf | 8 days |
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(fname 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(fname 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(fkey = 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(fTotal Amount to Pay: ₹total_amount:.2f) This project demonstrates: - Positional and default arguments - Mathematical logic - Function flexibility |
||


