From c8df7054596d185465c6e31618ff81282e229108 Mon Sep 17 00:00:00 2001 From: Gaurav Rattan <100664099+gauravrattan@users.noreply.github.com> Date: Mon, 14 Jul 2025 13:51:02 +0530 Subject: [PATCH 1/7] Create solutions.py --- day2/solution /solutions.py | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 day2/solution /solutions.py diff --git a/day2/solution /solutions.py b/day2/solution /solutions.py new file mode 100644 index 0000000..a81d174 --- /dev/null +++ b/day2/solution /solutions.py @@ -0,0 +1,40 @@ +# Task=1 + +def add_number(*args): + print(args) # Inside the function, args is a tuple + print(type(args)) + total = sum(args) + print(total) + +add_number(1, 2, 3) + + +# 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] Date: Mon, 14 Jul 2025 14:21:05 +0530 Subject: [PATCH 2/7] Create readme.md --- day2/solution /readme.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 day2/solution /readme.md diff --git a/day2/solution /readme.md b/day2/solution /readme.md new file mode 100644 index 0000000..6d6e706 --- /dev/null +++ b/day2/solution /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") +``` From 0acbd7a0bc351adb14153c7ca6c50aeb4d8e4098 Mon Sep 17 00:00:00 2001 From: Gaurav Rattan <100664099+gauravrattan@users.noreply.github.com> Date: Mon, 14 Jul 2025 16:31:53 +0530 Subject: [PATCH 3/7] Create solution.py --- day2/solutions/task2/solution.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 day2/solutions/task2/solution.py 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] Date: Mon, 14 Jul 2025 16:54:14 +0530 Subject: [PATCH 4/7] Create readme.md --- day2/solutions/task2/readme.md | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 day2/solutions/task2/readme.md 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") +``` From b4b2bf355892527d1f245a9fcee23bc6e7ee04ff Mon Sep 17 00:00:00 2001 From: Gaurav Rattan <100664099+gauravrattan@users.noreply.github.com> Date: Mon, 14 Jul 2025 16:55:03 +0530 Subject: [PATCH 5/7] Delete day2/solution directory --- day2/solution /readme.md | 39 ------------------------------------ day2/solution /solutions.py | 40 ------------------------------------- 2 files changed, 79 deletions(-) delete mode 100644 day2/solution /readme.md delete mode 100644 day2/solution /solutions.py diff --git a/day2/solution /readme.md b/day2/solution /readme.md deleted file mode 100644 index 6d6e706..0000000 --- a/day2/solution /readme.md +++ /dev/null @@ -1,39 +0,0 @@ -# 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/solution /solutions.py b/day2/solution /solutions.py deleted file mode 100644 index a81d174..0000000 --- a/day2/solution /solutions.py +++ /dev/null @@ -1,40 +0,0 @@ -# Task=1 - -def add_number(*args): - print(args) # Inside the function, args is a tuple - print(type(args)) - total = sum(args) - print(total) - -add_number(1, 2, 3) - - -# 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] Date: Mon, 14 Jul 2025 18:30:40 +0530 Subject: [PATCH 6/7] Create solution.py --- day2/solutions/task3/solution.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 day2/solutions/task3/solution.py diff --git a/day2/solutions/task3/solution.py b/day2/solutions/task3/solution.py new file mode 100644 index 0000000..d0f8eeb --- /dev/null +++ b/day2/solutions/task3/solution.py @@ -0,0 +1,17 @@ +# Task-3 + + +def fried_func(fried): + for i in fried: + for k,v in i.items(): + print(f'\t{k}:-{v}') + +for i in a_dict: + #print(i) + #print (i.items()) + for key,value in i.items(): + if isinstance(value,list): + print(f'{key}:- ') + fried_func(value) + else: + print(f'{key} :- {value}') From 09a2683d808c02f4dc8dc6531674f1415610d632 Mon Sep 17 00:00:00 2001 From: Gaurav Rattan <100664099+gauravrattan@users.noreply.github.com> Date: Mon, 14 Jul 2025 18:44:09 +0530 Subject: [PATCH 7/7] Create readme.md --- day2/solutions/task3/readme.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 day2/solutions/task3/readme.md diff --git a/day2/solutions/task3/readme.md b/day2/solutions/task3/readme.md new file mode 100644 index 0000000..2c7295f --- /dev/null +++ b/day2/solutions/task3/readme.md @@ -0,0 +1,31 @@ +# 🧾 User Info Printer + +This Python script traverses a nested dictionary structure and prints all user-related information, including each user's details and a list of their friends. + +--- + +## 🧠 Logic Breakdown + +1. Loop through each user in the list `a_dict`. +2. For each user (which is a dictionary), iterate through all key-value pairs using `.items()`. +3. If the value is a list (like the `"frieds"` key), pass it to the `fried_func()` to handle nested friend data. +4. Otherwise, print the key-value pair directly. +5. The `fried_func()` is a helper function that: + - Loops through each friend dictionary. + - Prints each friend’s information with a tab for better formatting. + +--- + +## 🧰 Function & Method Explanations + +### πŸ” `dict.items()` + +- In Python, the .items() method is a built-in dictionary method that returns a view object. This view object contains all the key-value pairs of the dictionary as tuples, where each tuple is in the format (key, value). + +#### Example: +```python +{"name": "gara"}.items() # ➝ [('name', 'gara')] +``` +### πŸ§ͺ `isinstance()` + +- isinstance(object, type) is used to check the type of a value at runtime.