diff --git a/day2/solutions/task2/readme.md b/day2/solutions/task2/readme.md new file mode 100644 index 0000000..6d6e706 --- /dev/null +++ b/day2/solutions/task2/readme.md @@ -0,0 +1,39 @@ +# Python: Understanding *args and **kwargs + +This mini project explains how to use `*args` and `**kwargs` in Python functions. These features help you write flexible, reusable, and dynamic functions that can handle varying numbers of inputs. + +--- + +## 📌 What is `*args`? + +- `*args` allows a function to accept any number of **positional arguments**. +- These arguments are stored as a **tuple** inside the function. +- Useful when you’re not sure how many values will be passed. + +### ✅ Example of `*args` + +```python +def add_numbers(*args): + total = sum(args) + print("Sum:", total) + +add_numbers(10, 20, 30) +``` + +--- + +## 📌 What is `**kwargs`? + +- `**kwargs` allows a function to accept any number of **keyword arguments**. +- These arguments are stored as a **dictionary** inside the function. +- Useful for handling optional or dynamic key-value inputs. + +### ✅ Example of `**kwargs` + +```python +def print_user_info(**kwargs): + for key, value in kwargs.items(): + print(f"{key}: {value}") + +print_user_info(name="Alice", age=25, city="London") +``` diff --git a/day2/solutions/task2/solution.py b/day2/solutions/task2/solution.py new file mode 100644 index 0000000..8dd0366 --- /dev/null +++ b/day2/solutions/task2/solution.py @@ -0,0 +1,29 @@ +# Task=2 + +def student_result(**kwargs): + print(kwargs) # Inside the function, kwargs is a dictionary + failed_marks=37 + total=0 + max_marks=0 + max_user='' + failed_user=[] + for name in kwargs: + total=total+kwargs[name] + + #for max user + if kwargs[name]>max_marks: + max_marks=kwargs[name] + max_user=name + + #for failed user + if kwargs[name]