Hi, can you do it in PYTHON def delete_item(...): """ param: info_list - a list from which to remove an item param: idx (str) - a string that is expected to contain an integer index of an item in the in_list param: start_idx (int) - an expected starting value for idx (default is 0); gets subtracted from idx for 0-based indexing The function first checks if info_list is empty. The function then calls is_valid_index() to verify that the provided index idx is a valid positive index that can access an element from info_list. On success, the function saves the item from info_list and returns it after it is deleted from info_list. returns: If info_list is empty, return 0. If is_valid_index() returns False, return -1. Otherwise, on success, the function returns the element that was just removed from info_list. Helper functions: - is_valid_index() """
Hi, can you do it in PYTHON
def delete_item(...):
"""
param: info_list - a list from which to remove
an item
param: idx (str) - a string that is expected to
contain an integer index of an item in
the in_list
param: start_idx (int) - an expected starting
value for idx (default is 0); gets
subtracted from idx for 0-based indexing
The function first checks if info_list is empty.
The function then calls is_valid_index() to verify
that the provided index idx is a valid positive
index that can access an element from info_list.
On success, the function saves the item from info_list
and returns it after it is deleted from info_list.
returns:
If info_list is empty, return 0.
If is_valid_index() returns False, return -1.
Otherwise, on success, the function returns the element
that was just removed from info_list.
Helper functions:
- is_valid_index()
"""
![Test Your Code
• Add the assertion tests - use the ones below + add your own.
####### DELETE OPTION
assert delete_item([], 1, 1) == 0
assert delete_item ([1], ¹-2¹) == -1
assert delete_item([1, 2, 3], ¹2¹) == 3
Back to top
Sample Program Flow
Below is the result of the user selecting D from the main menu:
You selected option D to>Delete.
Which category would you like to delete?
1 - PA (5 %)
2 - CA (15 %)
3- LA (25.0%)
4 - Quiz (25%)
5 - Project (25%)
---
::: Enter the number corresponding to the category.
> 5
Success!
Deleted Project (25%)
::: Would you like to delete another category? Enter 'y' to continue.
::: Press Enter to continue
We can verify that this deletion did indeed occur by listing the categories and noticing that the deleted category is no longer on the list.
When entering an invalid category information:
You selected option D to > Delete.
Which category would you like to delete?
1 - PA (5 %)
2 CA (15 %)
3-
4
LA (25.0%)
Quiz (25%)
::: Enter the number corresponding to the category.
> 0
WARNING: |0| is an invalid category number!](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fccac55ee-732b-4607-a38e-f5bd0a8aacb2%2F19e3f65c-15b7-41a6-8b5e-2762a2e7939c%2Fnxv2o0f_processed.png&w=3840&q=75)
![Instructions
This lab builds on the previous checkpoint labs.
In the main program, add the following lines to ask the user which category they want to delete:
elif opt == 'D':
Back to top
continue_action = 'y'
while continue_action == 'y':
print("Which category would you like to delete?")
print_grade_info (all_grades, show_grades = False)
print ("::: Enter the number corresponding to the category.")
user_option = input ("> ")
result = delete_item (all_grades, user_option, 1)
if type (result) == dict:
Back to top
print ("Success!")
# Get the deleted category name and weight
category= result["category"]
weight = result["weight"]
print (f"Deleted {category} ({weight} §) ")
elif result == 0: # delete_item() returned an error
print ("WARNING: there is nothing to delete.")
elif result == -1: # is_valid_index () returned False
print (f"WARNING: |{user_option}| is an invalid category number!")
print ("::: Would you like to delete another category?", end=" ")
continue_action = input ("Enter 'y' to continue.\n> ")
continue_action = continue_action.lower ()
Deleting a category
Define delete_item() in the functions.py (see the function stub below).
•
Implement this function according to the function documentation. Read the documentation carefully first, before
implementing anything.
Good news - you should have already implemented most of this functionality in the previous labs! :-)
•
• Add the tests from the Test Your Code section to your tests.py
•
Add (and run!) your own new assert statements - pay close attention to the cases described in the function documentation
that should cause errors.
• Test each case by writing separate assertions.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fccac55ee-732b-4607-a38e-f5bd0a8aacb2%2F19e3f65c-15b7-41a6-8b5e-2762a2e7939c%2Fawf1f6i_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images









