Skip to content

Commit

Permalink
update code comments and formatting #8
Browse files Browse the repository at this point in the history
  • Loading branch information
blahosyl committed Apr 14, 2024
1 parent aac79ec commit bead437
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,27 @@ class ShoppingList:
"""
Creates an instance of ShoppingList
"""

def __init__(self, list_data):
self.list_data = list_data

def print_formatted(self, ingredient_list):
""" Print ingredient list in a user-friendly string format"""
# print an empty line to visually separate the list
print('\n')
# for every item in the list
for i in range(0, len(ingredient_list)):
# print(shopping_list[i][0], shopping_list[i][1])
# set `print_string` as the first item of the list
print_string = ingredient_list[i][0]
# find the index of the opening bracket in the string
opening = print_string.index('(')
print_string = print_string[:opening-1] + ': ' + str(ingredient_list[i][1]) + print_string[opening-1:]
# 1 left of the opening bracket, add the following:
# a colon
# the quantity (second item of the list)
print_string = print_string[:opening - 1] \
+ ': ' \
+ str(ingredient_list[i][1]) \
+ print_string[opening - 1:]
print_string = print_string.replace('(', '')
print_string = print_string.replace(')', '')
print(print_string)
Expand Down

0 comments on commit bead437

Please sign in to comment.