def order_cookies(dessert_list): #Ask the uder for whatever kind of cookie they would like cookie_kind = input("What kind of cookies would you like? ") #Create a cookie object cookie1 = cookie.Cookie("Cookie", cookie_kind) #Ask the user how many cookies they would like new_quantity = int(input("How many cookies would you like? ")) #Validate that the number of cookies entered is correct while new_quantity <= 0: #Invalid quantity entered. Try again. new_quantity = int(input("Quantity must be positive. Please try again. ")) #Use the mutator to update the object's quantity cookie1.update_quantity(new_quantity) #Ask the user for the price per dozen new_price = float(input("What is the price per dozen? $")) #Validate that the price per dozen is valid while new_price <= 0: #Invalid price entered. Try again. new_price = float(input("Price per dozen must be positive. Please try again. $")) #Use the mutator to update the object's price per dozen cookie1.update_price_per_dozen(new_price) #Add the dessert to the list dessert_list.append(cookie1)
def test_part_two(self): "Test part two example of Cookie object" # 1. Create Cookie object from text myobj = cookie.Cookie(part2=True, text=aoc_15.from_text(PART_TWO_TEXT)) # 2. Check the part two result self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
def test_part_one(self): "Test part one example of Cookie object" # 1. Create Cookie object from text myobj = cookie.Cookie(text=aoc_15.from_text(PART_ONE_TEXT)) # 2. Check the part one result self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
def login_user(username): options = string.digits + string.ascii_letters token = "".join(random.choice(options) for _ in xrange(32)) user = db_player.get_by_username(username) user.token = token db_player.save(user) cookie.set_cookie( cookie.Cookie("username", username, [ cookie.CookieExpiresAttribute(datetime.datetime.utcnow() + datetime.timedelta(days=30)) ])) cookie.set_cookie( cookie.Cookie("token", token, [ cookie.CookieExpiresAttribute(datetime.datetime.utcnow() + datetime.timedelta(days=30)) ]))
class LogoutController(object): def __init__(self): pass cookie.set_cookie( cookie.Cookie("username", "", [ cookie.CookieExpiresAttribute(datetime.datetime.utcnow() - datetime.timedelta(days=30)) ])) cookie.set_cookie( cookie.Cookie("token", "", [ cookie.CookieExpiresAttribute(datetime.datetime.utcnow() - datetime.timedelta(days=30)) ])) def get_view(self): return ".view/logout.html"
def test_empty_init(self): "Test the default Cookie creation" # 1. Create default Cookie object myobj = cookie.Cookie() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(myobj.ingredients, [])
def test_text_init(self): "Test the Cookie object creation from text" # 1. Create Cookie object from text myobj = cookie.Cookie(text=aoc_15.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 2) self.assertEqual(len(myobj.ingredients), 2) # 3. Check methods self.assertEqual(myobj.score([44, 56]), 62842880)
def part_two(args, input_lines): "Process part two of the puzzle" # 1. Create the puzzle solver solver = cookie.Cookie(part2=True, text=input_lines) # 2. Determine the solution for part two solution = solver.part_two(verbose=args.verbose, limit=args.limit) if solution is None: print("There is no solution") else: print("The solution for part two is %s" % (solution)) # 3. Return result return solution is not None
def purchase_cookie(item_list, cost_list): #Define name name = "Cookie" #Prompt user for flavor of cookie kind = input("What flavor of cookie? ") #Capitilize user input kind = kind[0].upper() + kind[1:] #Create cookie object cookie_ordered = cookie.Cookie(name, kind) #Prompt user for price per dozen price = float(input("What is the price per dozen? $")) #Validate user input while cookie_ordered.update_price_per_dozen(pricee) == "FALSE": price = float(input("What is the price per dozen? $")) #Prompt user for quantity of cookies quantity = float(input("Number of cookies: ")) #Validate user input while cookie_ordered.update_quantity(quantity) == "FALSE": quantity = float(input("Number of cookies: ")) #Add object to list item_list.append(cookie_ordered) #Add cost to list cost_list.append(cookie_ordered.calculate_cost())
def main(): #Instantiating cookies chocolateChip = cookie.Cookie('chocolate chip', 10, 4.50) strawberry = cookie.Cookie('strawberry', 30, 3.00) sugar = cookie.Cookie('sugar', 15, 2.50) #Creating empty list cookieList = [] #Adding the three cookies into empty list cookieList.append(chocolateChip) cookieList.append(strawberry) cookieList.append(sugar) #Initializing for while loop menuChoice = 'a' #Looping menu choices while menuChoice != 'e': try: #Calling display menu function menuChoice = displayMenu().lower() #Decision making for menu choice 'a' if menuChoice == 'a': #Calling printAllCookies() function printAllCookies(cookieList) #Decision making for menu choice 'b' elif menuChoice == 'b': #Prompting for cookie type and price cookieType = input('Please enter the cookie type: ').lower() cookiePrice = float( input('Please enter the new price of the cookie: ')) print() #Calling setPrice() function newPrice = setPrice(cookieList, cookieType, cookiePrice) #Decision making if cookie type is not found if newPrice == 0: print('Cookie type not found.') print() #Decision making for menu choice 'c' elif menuChoice == 'c': #Prompting for cookie type cookieType = input('Please enter the cookie type: ').lower() #Calling outputCookieInventory() function inventory = outputCookieInventory(cookieList, cookieType) #Decision making if cookie type is not found if inventory == 0: print('Cookie type not found.') print() else: print('The inventory is ', inventory) print() except ValueError: print('Value error.') print() except Exception as err: print(err) print()
def main(): my_flat = flat.Flat() print("\nInitial state(1) of my house:\n") print(my_flat) print("\nLets wash the windows and make the bed!") my_flat.set_windows("Washed") my_flat.set_bed("Made") print("\nState 2:\n") print(my_flat) print("\nLets dust the surfaces and vacuum the floors!") my_flat.set_surface("Dusted") my_flat.set_floors("Vacuumed") print("\nState 3:\n") print(my_flat) print("\nLets go shop for food and toiletpaper!") my_flat.set_fridge("Full of food") my_flat.set_toilet_paper("Enough") print("\nState 4:\n") print(my_flat) print("\nHmm, better get more toiletpaper. Just to make sure...") my_flat.set_toilet_paper("More than enough") print("\nState 5:\n") print(my_flat) # Task 3: Cookie # Create cookies with random flavors and then bake them. print("*"*20) print("Time to bake some cookies! Lets make 10!") cookies = {} for i in range(10): cookies[i+1] = cookie.Cookie("Round") cookies[i+1].set_random_flavor() cookies[i+1].set_baked() # Print all cookies for key in cookies: print("\n") print(cookies[key]) # Frost the new 10 cookies print("\nLets frost those badboys!") for key in cookies: cookies[key].set_frosted() # Print all cookies for key in cookies: print("\n") print(cookies[key]) # Ask the user if his/her flavor is present. If not, create a new cookie. checking = True while checking: check_flavor = input("\nIs your favorite flavor present?(y/n) ") if check_flavor == "y": break elif check_flavor == "n": fav_flav = input("\nWhats your favorite flavor: ") cookies[len(cookies)+1] = cookie.Cookie("Round", fav_flav) cookies[len(cookies)].set_baked() cookies[len(cookies)].set_frosted() break else: print("\nUse the key y or n.") # Print all cookies. for key in cookies: print("\n") print(cookies[key])
def main(): # instatiates c1,c2,c3 as objects from the Cookie class c1 = cookie.Cookie("chocolate chip", 10, 4.50) c2 = cookie.Cookie("strawberry", 30, 3.00) c3 = cookie.Cookie("sugar", 15, 2.50) # creates an empty list clist = [] #adds c1, c2, c3 to the empty clist clist.append(c1) clist.append(c2) clist.append(c3) def displayChoice(): def printAllCookies(cList): for i in cList: example = cookie.Cookie.__str__(i) print(example) print() def changePrice(cList, cookieType, pRice): flag = 0 for i in cList: if i.get_cType() == cookieType: flag = 1 i.set_price = pRice break return flag def outputCookieInventory(cList, cookieType): for i in cList: flag1 = 0 if i.get_cType() == cookieType: flag1 = 1 break return i.get_inventory() # the following block of code is the menu print("Welcome to Best Cookies") print("===========================") print("a: Output information for all cookies") print("b: Set a new price for one cookie") print("c: Output inventory for a specific cookie") print("e: Exit the program \n") choice = 'zar' while choice != 'e': # the initial prompt for menu choice choice = input("Please enter your choice: ").lower() print("\n") #the following decision tree processees the choice choicelist = ['a', 'b', 'c', 'e'] if choice == 'a': printAllCookies(clist) elif choice == 'b': cookietype = input( "What cookietype you want to change the price of?").lower( ) price = float( input("What do you want to change the cookie price to?")) flag = changePrice(clist, cookietype, price) if flag == 0: print("COOKIE TYPE NOT FOUND") elif choice == 'c': cookietype = input("What cookie type do you want?") number = outputCookieInventory(clist, cookietype) print("The inventory for", cookietype, "is", number) elif choice == 'e': print("You just chose to exit the program") else: print( "you just made an invalid input, you will be prompted again in a moment" ) displayChoice()