2
2
This program made by Joe S
3
3
"""
4
4
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
7
7
8
- object_list = []
8
+ object_list = [] # Create an empty list where we will store objects
9
9
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
12
12
self .name = name
13
13
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
15
15
print ("Total ounces of " + self .name + ": " + str (float (self .qty ) * servings ))
16
16
17
- for listitem in shopping_list :
17
+ for listitem in shopping_list : # For every item on our shopping list
18
18
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
20
20
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