0% found this document useful (0 votes)
16 views2 pages

P 62.2 Args Kwargs in Python - Practice

The document outlines a series of function definitions in Python, each designed to perform specific tasks such as summing numbers, greeting people, and managing user information. Functions include handling variable arguments, keyword arguments, and returning or printing results based on the inputs provided. Overall, it serves as a guide for creating versatile and flexible functions for various programming needs.

Uploaded by

karamohamedamr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

P 62.2 Args Kwargs in Python - Practice

The document outlines a series of function definitions in Python, each designed to perform specific tasks such as summing numbers, greeting people, and managing user information. Functions include handling variable arguments, keyword arguments, and returning or printing results based on the inputs provided. Overall, it serves as a guide for creating versatile and flexible functions for various programming needs.

Uploaded by

karamohamedamr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Sum of Numbers

Write a function sum_numbers(*args) that takes an arbitrary number of numbers as


input and returns their sum.

Product of Numbers
Write a function product_numbers(*args) that takes an arbitrary number of numbers
as input and returns their product.

Greet Multiple People


Write a function greet_people(*names) that takes an arbitrary number of names as
input and prints a greeting for each name.

Personal Information
Write a function display_info(name, age, **kwargs) that takes a name and age as
required arguments, and additional keyword arguments for extra information (like
city, profession) and prints all the information.

Build Profile
Write a function build_profile(first, last, **user_info) that builds a dictionary
containing everything we know about a user.

Calculate Total Cost


Write a function calculate_total_cost(price, *discounts, tax=0.05) that takes a
price, an arbitrary number of discounts, and an optional tax rate, and returns the
final cost after applying the discounts and tax.

Order Sandwich
Write a function order_sandwich(bread, *ingredients, **options) that prints the
bread type, ingredients, and options for a sandwich order.

Pack Items
Write a function pack_items(container, *items, **labels) that prints the container,
items, and labels for each item.

Flexible Greet
Write a function flexible_greet(*args, greeting="Hello", **kwargs) that prints a
greeting followed by the positional arguments and keyword arguments.

Sum and Info


Write a function sum_and_info(*numbers, **info) that returns the sum of the numbers
and prints the additional information provided through keyword arguments.

Categorize Items
Write a function categorize_items(*items, category="Misc") that prints each item
along with its category.

User Details
Write a function user_details(name, *args, **kwargs) that prints the name and any
additional positional and keyword arguments provided.

Shopping List
Write a function shopping_list(shop_name, *items, **options) that prints the shop
name, items to buy, and additional options like delivery or pickup.

Sum and Print


Write a function sum_and_print(a, b, *args) that sums two required arguments and
any additional arguments, and prints the result.

Personalized Greeting
Write a function personalized_greeting(greeting, *names, **details) that prints a
personalized greeting for each name along with additional details.

Find Max
Write a function find_max(*args) that takes an arbitrary number of numbers and
returns the maximum value.

Join Strings
Write a function join_strings(separator, *args) that joins all the strings provided
with the given separator and returns the result.

Display Arguments
Write a function display_arguments(*args, **kwargs) that prints all positional and
keyword arguments.

Update Inventory
Write a function update_inventory(inventory, *items, **details) that updates the
inventory dictionary with items and additional details like quantity or price.

Student Grades
Write a function student_grades(student, *grades, **comments) that prints the
student's name, grades, and any additional comments.

You might also like