How to use contains_list method in localstack

Best Python code snippet using localstack_python

Coffee.py

Source:Coffee.py Github

copy

Full Screen

1#重启前的初始数据2contains_list ={"Water":100,3 "Milk":100,4 "Coffe": 100,5 "Mocha": 100}6kinds_list = {"Cappuccino": 0,7 "Latte": 0,8 "Mocha": 0,9 "CafeAmericano": 0,10 "Espresso" : 0}11#函数封装:1.方便循环。2.方便双重循环的跳出。12def coffee():13 menu_list =[14 {"id": 1, "name":"1.Cappuccino","contains":"[Water: 50ml; Milk: 50ml; Coffee: 50ml]:","price":12,"$":"¥"},15 {"id": 2, "name":"2.Latte","contains":"[Water: 80ml; Milk: 20ml; Coffee: 50ml]:", "price": 10,"$":"¥"},16 {"id": 3, "name":"3.Mocha","contains":"[Water: 50ml; Milk: 50ml; Coffee: 40ml; Mocha: 10ml]:", "price": 15,"$":"¥"},17 {"id": 4, "name":"4.Cafe Americano", "contains":" [Water: 100ml; Milk: 0ml; Coffee: 50ml]:","price": 10,"$":"¥"},18 {"id": 5, "name":"5.Espresso","contains":" [Water: 70ml; Milk: 0ml; Coffee: 80ml]:","price":14,"$":"¥"},19 {"id": 6, "name":" Quit [Q/q]","contains":" ","price":" ","$":" "}]20 print('##############################################################################\n'21 "##################A nice day starts with a cup of coffee! ####################\n"22 '##############################################################################')23 for menu in menu_list:#从字典取值24 print(menu.get('name'),menu.get('contains'),menu.get('price'),menu.get('$'))25 26 i = 0#用变量来引导前后循环过程,单次循环27 while i < 1: 28 print('#'*78)29 server1 = (input("$ please select your item:(Q/q to quit):"))30 i = i + 131 if server1 == '1':#判断字典中储存数据是否够32 if contains_list["Water"] >= 50 and contains_list["Milk"] >= 50 and contains_list["Coffe"] >= 50:33 price = 12#拟定价格34 break#跳出循环35 else:36 print("your item is inavailable , back to menu")#无效输入返回函数37 coffee()38 elif server1 == '2':39 if contains_list["Water"] >= 80 and contains_list["Milk"] >= 20 and contains_list["Coffe"] >= 50:40 price = 1041 break42 else:43 print("your item is inavailable , back to menu")44 coffee()45 elif server1 == '3':46 if contains_list["Water"] >= 50 and contains_list["Milk"] >= 50 and contains_list["Coffe"] >= 40 and contains_list["Mocha"] >= 10:47 price = 1548 break49 else:50 print("your item is inavailable , back to menu")51 coffee()52 elif server1 == '4':53 if contains_list["Water"] >= 100 and contains_list["Coffe"] >= 50:54 price = 1055 break56 else:57 print("your item is inavailable , back to menu")58 coffee()59 elif server1 == '5':60 if contains_list["Water"] >= 70 and contains_list["Coffe"] >= 80:61 price = 1462 break63 else:64 print("your item is inavailable , back to menu")65 coffee()66 elif server1 == 'q':67 exit()#重启函数68 elif server1 == 'Q':69 exit()70 else:71 coffee()72 while True:#继续操作判断73 server2 = input("your item is available, please enter 'c' to continue:")74 if server2 == 'c':75 break76 else:77 continue78 #判断是否使用优惠券79 #使用函数封装(此处为coffee())80 try:#使用try……finally使函数跳出双循环后继续执行之后的代码81 while True:#外循环82 coupon = input("a coupon is available? [y/n]: ")83 if coupon == 'y':84 while True:#内循环85 number = input("please enter your coupon No.(Q/q to quit):")86 if number == '666':87 price = float(price*0.6)88 print("you have a coupon with 60% discount, your item price is:")89 print(price)90 return#跳出函数91 elif number == '888':92 price = float(price * 0.8)93 print("you have a coupon with 80% discount, your item price is:")94 print(price)95 return96 elif number == 'q':97 break#跳出内循环,继续外循环98 elif number == 'Q':99 break100 else:101 print("wrong number!")102 continue#继续内循环103 elif coupon == 'n':104 print("you have a coupon with no discount, your item price is:")105 print(price)106 break#跳出外循环,继续函数107 else:108 continue#继续内循环109 finally:#跳出后继续函数110 #判断金额111 cash = float(0)112 if cash <= price:#首次条件判断113 cash20 = float(input("please enter your cash, how many 20¥count? :"))114 cash10 = float(input("how many 10¥count? :"))115 cash5 = float(input("how many 5¥count? :"))116 cash1 = float(input("how many 1¥count? :"))117 cash = cash1 + cash5*5 + cash10*10 + cash20*20 + cash118 print("your total amount is: " + str(cash))119 while True:120 if cash <= price:#循环条件判断121 server3 = input("you have not enough money amount for buying, please continue to enter your cash [c] or quit with [q]: ")122 if server3 == 'c':#循环123 cash20 = float(input("how many 20¥count? :"))124 cash10 = float(input("how many 10¥count? :"))125 cash5 = float(input("how many 5¥count? :"))126 cash1 = float(input("how many 1¥count? :"))127 cash = cash1 + cash5*5 + cash10*10 + cash20*20 + cash128 print("your total amount is: 1" + str(cash))129 continue130 elif server3 == 'q':131 coffee()132 elif server3 == 'Q':133 coffee()134 elif cash > price:#判断成功后,打印结束语句135 charge = float(cash - price)136 print("your change is: "+ str(charge) + " please receipt it. ")137 print("your coffee is making:\n"138 "……………………………….\n"139 "## coffee preparing finished!\n"140 "……………………………….\n"141 "## coffee making finished!\n"142 "……………………………….\n"143 "## coffee packaging finished!\n\n\n\n\n")144 145 break146 #记录售卖情况147 if server1 == '1':148 kinds_list["Cappuccino"] = kinds_list["Cappuccino"] + 1149 elif server1 == '2':150 kinds_list["Latte"] = kinds_list["Latte"] + 1151 elif server1 == '3':152 kinds_list["Mocha"] = kinds_list["Mocha"] + 1153 elif server1 == '4':154 kinds_list["CafeAmericano"] = kinds_list["CafeAmericano"] + 1155 elif server1 == '5':156 kinds_list["Espresso"] = kinds_list["Espresso"] + 1157 print("The items sold on this machine are:\n"158 "# Cappuccino: " + str(kinds_list["Cappuccino"]) +"\n"159 "# Latte: " + str(kinds_list["Latte"]) +"\n"160 "# Mocha: " + str(kinds_list["Mocha"]) +"\n"161 "# Cafe Americano: " + str(kinds_list["CafeAmericano"]) +"\n"162 "# Espresso: " + str(kinds_list["Espresso"]) +"\n"163 "### Total profile:"+ str(price))164 #最终确定更改字典中的数据165 if server1 == '1':166 contains_list["Water"] = contains_list["Water"] - 50167 contains_list["Milk"] = contains_list["Milk"] - 50168 contains_list["Coffe"] = contains_list["Coffe"] - 50169 elif server1 == '2':170 contains_list["Water"] = contains_list["Water"] - 80171 contains_list["Milk"] = contains_list["Milk"] - 20172 contains_list["Coffe"] = contains_list["Coffe"] - 50173 elif server1 == '3':174 contains_list["Water"] = contains_list["Water"] - 50175 contains_list["Milk"] = contains_list["Milk"] - 50176 contains_list["Coffe"] = contains_list["Coffe"] - 40177 contains_list["Mocha"] = contains_list["Mocha"] - 10178 elif server1 == '4':179 contains_list["Water"] = contains_list["Water"] - 100180 contains_list["Coffe"] = contains_list["Coffe"] - 50181 elif server1 == '5':182 contains_list["Water"] = contains_list["Water"] - 70183 contains_list["Coffe"] = contains_list["Coffe"] - 80184 coffee()#将数据传到下个循环185coffee()#第一次执行函数186#收获187#1.先用函数封装,再使用try…finally来使跳出双循且结束的部分继续运行之后的代码,这样双跳和单跳都能在同一函数的同一双重循环里运行。188#2.字典确定键值对,然后扔到函数中循环使用就可以了。像变量啊元组都不可以更改地址,但是列表或者字典可以,所以就能保留上一次循环的结果。189#3.不可更改数值更换的是地址指向,称为值传递。190#4.另外一种方法就是把数据储存到库中,在使用时调用数据库一遍一遍覆写,这样就可以永久性更改数值。想恢复数据的话就整个恢复保存的初始数据库。191#总结:有一实际参数a,在调用时又产生一个新的变量x(形式参数),x和a指向相同的地址。如果对x赋值,意味着改变了x指向的内存块,而不改变a的值、...

Full Screen

Full Screen

day_07.py

Source:day_07.py Github

copy

Full Screen

1import os23curr_dir = os.path.dirname(os.path.abspath(__file__))45f = open(os.path.join(curr_dir, "data.txt"))6# f = open(os.path.join(curr_dir, "test_part_2.txt"))7txt = f.readlines()8f.close()910txt_cleaned = [item.strip() for item in txt]1112# print(txt_cleaned)1314bag_rule_dict = {}1516for line in txt_cleaned:17 rule_components = line.split("contain")18 own_color = rule_components[0][:-6]1920 contains_list_input = rule_components[1].strip().split(", ")21 contains_list_output = []2223 for content in contains_list_input:24 # print(content)2526 if content == "no other bags.":27 contains_list_output = None28 else:29 content_split = content.split()30 quantity = int(content_split[0])31 bag_color = f"{content_split[1]} {content_split[2]}"3233 contains_list_output.append({"color": bag_color, "quantity": quantity})3435 bag_rule_dict[own_color] = contains_list_output363738class bag:39 def __init__(self, color, rule_dict):40 self.own_color = color41 self.contains_list = []4243 self.contains_list = rule_dict[color]4445 def get_own_color(self):46 return self.own_color4748 def fill_bag(self, rule_dict):49 if not self.contains_list is None:50 for item in self.contains_list:51 item["bag"] = bag(item["color"], rule_dict)52 item["bag"].fill_bag(rule_dict)5354 def is_color_in_bag(self, color):55 answer = False5657 if self.contains_list is None:58 pass59 else:60 for entry in self.contains_list:61 if entry["color"] == color:62 answer = True6364 if answer == False:65 if self.contains_list is None:66 pass67 else:68 for entry in self.contains_list:69 if entry["bag"].is_color_in_bag(color):70 answer = True71 break7273 return answer7475 def number_bags_with_self(self):76 number = 17778 if self.contains_list is None:79 pass80 else:81 for entry in self.contains_list:82 number += entry["quantity"] * entry["bag"].number_bags_with_self()8384 return number858687bag_list = []8889for bag_color in bag_rule_dict:90 # print(bag_color)91 bag_n = bag(bag_color, bag_rule_dict)92 bag_n.fill_bag(bag_rule_dict)93 bag_list.append(bag_n)9495# Part 1.96number_bags = 09798for bag in bag_list:99 if bag.is_color_in_bag("shiny gold"):100 number_bags += 1101102print(f"Number of bags containing shiny gold: {number_bags}")103104# Part 2.105106for bag in bag_list:107 if bag.get_own_color() == "shiny gold":108 number_contained_bags = bag.number_bags_with_self()109 ...

Full Screen

Full Screen

finder.py

Source:finder.py Github

copy

Full Screen

1import json2# load words from json file3with open('words_5_letters.json', 'r', encoding='utf-8') as f:4 words = json.load(f)5 persian_words = words['vaajoor']6 english_words = words['wordle']7def word_finder(game_mode: str, exact_dict: dict, contains_list: list, not_contains_list: list):8 if len(contains_list) == 0 and len(exact_dict.keys()) == 0 and len(not_contains_list) == 0:9 return {'message': 'No condition', 'result': [], 'result_count': 0}10 condition = ''11 if len(exact_dict.keys()) > 0:12 condition = ' and '.join([f'word[{key}] == "{exact_dict[key]}"' for key in exact_dict])13 if len(contains_list) > 0 and len(exact_dict.keys()) > 0:14 condition += ' and '15 if len(contains_list) > 0:16 condition += ' and '.join([f'"{character}" in word' for character in contains_list])17 if len(not_contains_list) > 0 and (len(exact_dict.keys()) > 0 or len(contains_list) > 0):18 condition += ' and '19 if len(not_contains_list) > 0:20 condition += ' and '.join([f'"{character}" not in word' for character in not_contains_list])21 if game_mode == 'vaajoor':22 words_dictionary = persian_words23 elif game_mode == 'wordle':24 words_dictionary = english_words25 else:26 return {'message': 'Mode not acceptable', 'result': [], 'result_count': 0}27 all_acceptable_words = []28 for word in words_dictionary:29 if eval(condition):30 all_acceptable_words.append(word)31 if len(all_acceptable_words) == 0:32 return {'message': 'No words were found', 'result': [], 'result_count': 0}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful