Course Content
Intermediate Python: Arguments, Scopes and Decorators
Intermediate Python: Arguments, Scopes and Decorators
Challenge: kwargs
Task
Write a Python function named create_user_profile
that accepts various user attributes as keyword arguments and formats them into a user profile string.
Functionality:
- The function should iterate over the
kwargs
and construct a string that lists each attribute and its value in a readable format. - Handle the case where no attributes are provided.
Output:
Return a string representing the user profile.
- Check if the
kwargs
dictionary is empty; - Unpack each key-value pair in
kwargs
using a for loop; - Used method
items()
. This is the method to iterate over both keys and values in a dictionary; - Use the
append
method. This will add each formatted key-value pair to theprofile_parts
list; - Call the function with keyword arguments.
Thanks for your feedback!
Challenge: kwargs
Task
Write a Python function named create_user_profile
that accepts various user attributes as keyword arguments and formats them into a user profile string.
Functionality:
- The function should iterate over the
kwargs
and construct a string that lists each attribute and its value in a readable format. - Handle the case where no attributes are provided.
Output:
Return a string representing the user profile.
- Check if the
kwargs
dictionary is empty; - Unpack each key-value pair in
kwargs
using a for loop; - Used method
items()
. This is the method to iterate over both keys and values in a dictionary; - Use the
append
method. This will add each formatted key-value pair to theprofile_parts
list; - Call the function with keyword arguments.
Thanks for your feedback!
Challenge: kwargs
Task
Write a Python function named create_user_profile
that accepts various user attributes as keyword arguments and formats them into a user profile string.
Functionality:
- The function should iterate over the
kwargs
and construct a string that lists each attribute and its value in a readable format. - Handle the case where no attributes are provided.
Output:
Return a string representing the user profile.
- Check if the
kwargs
dictionary is empty; - Unpack each key-value pair in
kwargs
using a for loop; - Used method
items()
. This is the method to iterate over both keys and values in a dictionary; - Use the
append
method. This will add each formatted key-value pair to theprofile_parts
list; - Call the function with keyword arguments.
Thanks for your feedback!
Task
Write a Python function named create_user_profile
that accepts various user attributes as keyword arguments and formats them into a user profile string.
Functionality:
- The function should iterate over the
kwargs
and construct a string that lists each attribute and its value in a readable format. - Handle the case where no attributes are provided.
Output:
Return a string representing the user profile.
- Check if the
kwargs
dictionary is empty; - Unpack each key-value pair in
kwargs
using a for loop; - Used method
items()
. This is the method to iterate over both keys and values in a dictionary; - Use the
append
method. This will add each formatted key-value pair to theprofile_parts
list; - Call the function with keyword arguments.