he list of lists. Call is_valid_index(idx, main_list) to check the validity of the index; returns -3 if `idx` is negative or exceeds the size of `in_list`. Call create_category(info_str) to add the category to the main list; returns the result of calling create_category(), which is a list if the update succeeds or an integer indicating an error. """ pass  elif opt == ...: # add the appropriate option key from the menu print_categories(all_categories) print("Which category would you like to update?") print("Enter the number corresponding to the category.") user_option = input() if not user_option.isdigit(): print(f"WARNING: `{user_option}` is an invalid category number!") else: idx = int(user_option) - 1 if not is_valid_index(idx, all_categories): print(f"WARNING: `{user_option}` is an invalid c

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
  1. Use the main template provided in the breakout room activity onto your IDE.
  2. Add the implementation for the print_categories(), is_valid_index() and update_category() functions
  3. Test your implementations by running the assert tests in the test file.

Requirements

You will need to implement the following functions.

def print_categories(main_list):

""" Given a list of lists, for each list stored in main_list, output its contents as follows: f"{index of category}. {item[0]} - {item[1]}%". note that indexing must start at 1 for the first item, not 0, which is first item's actual index in main_list. If `main_list` is empty, the function prints "There are no categories." Returns the number of categories. """

pass def is_valid_index(idx, in_list):

""" Checks whether the provided index `idx` is a valid positive index that can retrieve an element from `in_list`. Returns False if `idx` is negative or exceeds the size of `in_list` - 1. """

pass def update_category(info_str, idx, main_list):

""" Given a string with the category information and an integer index of the category that needs to be updated in the list of lists. Call is_valid_index(idx, main_list) to check the validity of the index; returns -3 if `idx` is negative or exceeds the size of `in_list`. Call create_category(info_str) to add the category to the main list; returns the result of calling create_category(), which is a list if the update succeeds or an integer indicating an error. """

pass

 elif opt == ...: # add the appropriate option key from the menu

print_categories(all_categories) print("Which category would you like to update?")

print("Enter the number corresponding to the category.")

user_option = input()

if not user_option.isdigit():

print(f"WARNING: `{user_option}` is an invalid category number!")

else: idx = int(user_option) - 1

if not is_valid_index(idx, all_categories):

print(f"WARNING: `{user_option}` is an invalid category number!")

else: print(f"Updating category {all_categories[idx][0]}")

print("Enter the category name and percentage: ") cat_info = input() cat_list = update_category(cat_info, idx, all_categories)

if type(cat_list) == list:

all_categories[idx] = cat_list

else:

print("WARNING: invalid category information!") print(f"Category information `{cat_info}` was not added.")

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY