Skip to content

Commit 5241910

Browse files
committed
Add Comments to recipe.py
1 parent 1040614 commit 5241910

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

CodeHS/3/5/9/recipe.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
This program made by Joe S
33
"""
44

5-
servings = -1
6-
shopping_list = ["mixed greens", "blueberries", "walnuts"]
5+
servings = -1 # Set the servings to a null value
6+
shopping_list = ["mixed greens", "blueberries", "walnuts"] # Create a list of all the things we need to shop for
77

8-
object_list = []
8+
object_list = [] # Create an empty list where we will store objects
99

10-
class ingredient():
11-
def __init__(self, name, qty):
10+
class ingredient(): # This class defines the ingredient object
11+
def __init__(self, name, qty): # This init function takes the name and qty, and asigns it to the object in question
1212
self.name = name
1313
self.qty = qty
14-
def list_total(self):
14+
def list_total(self): # This function lists the content of the current item in a human readable way
1515
print("Total ounces of " + self.name + ": " + str(float(self.qty) * servings))
1616

17-
for listitem in shopping_list:
17+
for listitem in shopping_list: # For every item on our shopping list
1818
print("Enter ingredient 1: " + str(listitem))
19-
object_list.append(ingredient(listitem, input("Ounces of " + str(listitem) + ": ")))
19+
object_list.append(ingredient(listitem, input("Ounces of " + str(listitem) + ": "))) # Create a new object, add it to our list using inputs from the user
2020

21-
servings = float(input("Enter total number of servings: "))
22-
print("")
23-
for item in object_list:
24-
item.list_total()
21+
servings = float(input("Enter total number of servings: ")) # Ask the user for the total number of servings
22+
print("") # Print a blank line
23+
for item in object_list: # For every object in our object list
24+
item.list_total() # call that objects respective list_total function

0 commit comments

Comments
 (0)