Write a function create_task that creates a dictionary to store the information for a single task. This function takes two parameters: a list with the keys and a list with the corresponding values and returns a dictionary with the provided keys mapping to the corresponding values. In our main program, we will create a list with the keys that allow us to capture: the name of the task (a string) description (a string) due date (a list) priority (an integer) In the main program, create a list called task_fields that stores these keys: task_fields = ["name", "description", "due date", "priority"] Do not hardcode these fields in the function -- they are provided as the argument into the function. Loop over each key to ask the user to input the corresponding information
Write a function create_task that creates a dictionary to store the information for a single task. This function takes two parameters: a list with the keys and a list with the corresponding values and returns a dictionary with the provided keys mapping to the corresponding values.
In our main program, we will create a list with the keys that allow us to capture:
- the name of the task (a string)
- description (a string)
- due date (a list)
- priority (an integer)
In the main program, create a list called task_fields that stores these keys:
task_fields = ["name", "description", "due date", "priority"]Do not hardcode these fields in the function -- they are provided as the argument into the function.
Loop over each key to ask the user to input the corresponding information. Assemble it into a new list.
Call create_task with these two lists as an input to get the dictionary with the task information.
Print the resulting dictionary from the main program.
When running the program, you could see the following prompts with the sample user input (note that the resulting dictionary is printed by the main program, not by the function):
Enter the task name: Do homework Enter the task description: Finish reading Chapter 7 Enter the task due date: 02/18/2022 Enter the task priority: 5 {'name': 'Do homework', 'description': 'Finish reading Ch7', 'due date': '02/18/2022', 'priority': '5'}def create_task(keys, vals):
"""
The function takes a list with the keys and a list
with the corresponding values and returns a dictionary
with the provided keys mapping to the corresponding values.
"""
pass
if __name__ == "__main__":
task_fields = ["name", "description", "due date", "priority"]
for field in task_fields:
print(f"Enter the task {field}:")
value = input()
print("FIXME: finish the program")
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images