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()     """

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

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!
Transcribed Image Text: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!
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.
Transcribed Image Text: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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education