Best Python code snippet using robotframework-pageobjects_python
lab3.py
Source:lab3.py
1__author__ = 'Fernando Ames'2# This program calculates a final price and the shipping time.3# Input List: item_price, location_of_user4# Output list: discount_price, time_of_shipping, final_price, location_of_user5# Function Real, String get_location_of_user_and_price()6# Declare Real item_price,7# Declare String location_of_user8#9# Display "Please enter the price of the item"10# Input item_price11# Display "Please enter the location North America, South America or Central America?"12# Input location_of_user13# Return item_price, location_of_user14# End Function15def get_location_of_user_and_price():16 item_price = 0.017 location_of_user = ""18 item_price = float(input("Please enter the item price: "))19 location_of_user = input("Please enter your location North America, South America or Central America?")20 return item_price, location_of_user21# Function Real calculate_discount_price(Real item_price)22# Declare Real discount_price23#24# if item_price >= 100.0 or item_price <= 200.0 then25# discount_price = 1026# Else27# discount_price = 028# End if29# Return discount_price30# End Function31def calculate_discount_price(item_price):32 discount_price = 0.033 if item_price >= 20.0:34 discount_price = 235 else:36 discount_price = 037 return discount_price38# Function Real calculate_total_price(Real item_price, Real discount_price)39# Declare total_price = 0.040#41# total_price = item_price - discount_price42# Return total_price43# End Function44def calculate_total_price(item_price, discount_price):45 total_price = 0.046 total_price = item_price - discount_price47 return total_price48# Function Real calculate_time_of_shipping(String location_of_user)49# Declare Real shipping_time50#51# if location_of_user == "North America" then52# shipping_time = 353# elif location_of_user == "Central America" then54# shipping_time = 555# elif location_of_user == "South America" then56# shipping_time = 757# else58# shipping_time = 1059# End if60# return shipping_time61# End Function62def calculate_time_of_shipping(location_of_user):63 shipping_time = 064 if location_of_user == "North America":65 shipping_time = 366 elif location_of_user == "Central America":67 shipping_time = 568 elif location_of_user == "South America":69 shipping_time = 770 else:71 shipping_time = 1072 return shipping_time73# Module output_price_and_shipping (Real discount_price, Real total_price, Real shipping_time, String location_of_user)74# Display "The location of the user is", location_of_user, "your shipping time is" shipping_time75# Display "Lucky day you received a -$", discount_price, "discount!"76# Display "Your total price is:", total_price77# End Module78def output_price_and_shipping(discount_price, total_price, shipping_time, location_of_user):79 print("The location of the user is", location_of_user, "and your shipping time is", shipping_time, "days")80 print("Lucky day! You received a -$", discount_price, "discount!")81 print("Your total price is:$", total_price)82# Module calculate_price_and_shipping()83# Declare Real item_price84# Declare String location_of_user85# Declare Real discount_price86# Declare Real total_price87# Declare Real shipping_time88#89# Set item_price, location_of_user = get_location_of_user_and_price()90# Set discount_price = calculate_discount_price(item_price)91# Set total_price = calculate_total_price(item_price, discount_price)92# Set shipping_time = calculate_time_of_shipping(location_of_user)93# Call output_price_and_shipping(discount_price, total_price, shipping_time, location_of_user)94# End Module95def calculate_price_and_shipping():96 item_price = 0.097 location_of_user = ""98 discount_price = 0.099 total_price = 0.0100 shipping_time = 0101 item_price, location_of_user = get_location_of_user_and_price()102 discount_price = calculate_discount_price(item_price)103 total_price = calculate_total_price(item_price, discount_price)104 shipping_time = calculate_time_of_shipping(location_of_user)105 output_price_and_shipping(discount_price, total_price, shipping_time, location_of_user)...
__init__.py
Source:__init__.py
...18class PricePolicy(object):19 def __init__(self, injector, rules):20 self.injector = injector21 self.rules = rules22 def floor_price(self, equity_pair, price):23 assert equity_pair in self.rules, "equity_pair {} should be member of rules.".format(equity_pair)24 price_min = self.rules[equity_pair].min25 price_max = self.rules[equity_pair].max26 price_step = self.rules[equity_pair].step27 if price_min is not None and price < price_min:28 return 029 if price_max is not None and price > price_max:30 return price_max31 if price_step is not None:32 if price_step <= 1:33 price_multiplier = 1 / price_step34 return math.floor(float(price) * price_multiplier) / price_multiplier35 else:36 return price_step * math.floor(float(price) / price_step)37 return price38 def ceil_price(self, equity_pair, price):39 assert equity_pair in self.rules, "equity_pair {} should be member of rules.".format(equity_pair)40 price_min = self.rules[equity_pair].min41 price_max = self.rules[equity_pair].max42 price_step = self.rules[equity_pair].step43 if price_min is not None and price < price_min:44 return price_min45 if price_max is not None and price > price_max:46 # probably raise exception?47 return price_max48 if price_step is not None:49 if price_step <= 1:50 price_multiplier = 1 / price_step51 return math.ceil(float(price) * price_multiplier) / price_multiplier52 else:53 return price_step * math.ceil(float(price) / price_step)54 return price55 @staticmethod56 def build(injector, config_path):57 rules = PricePolicy.parse_rules(config_path)58 return PricePolicy(injector, rules)59 @staticmethod60 def parse_rules(config_path):61 with open(config_path, 'rU') as f:62 conf = json.load(f)63 rules = {}64 for equity_pair in conf:65 min = None66 max = None67 step = None68 if 'price' in conf[equity_pair]:69 price_conf = conf[equity_pair]['price']70 if 'min' in price_conf:71 min = price_conf['min']72 if 'max' in price_conf:73 max = price_conf['max']74 if 'step' in price_conf:75 step = price_conf['step']76 price_rule = PriceRule(min, max, step)77 rules[equity_pair] = price_rule78 return rules79class DummyPricePolicy(PricePolicy):80 def __init__(self, injector):81 super(DummyPricePolicy, self).__init__(injector, {})82 def floor_price(self, equity_pair, price):83 return price84 def ceil_price(self, equity_pair, price):85 return price86class PriceRule(object):87 def __init__(self, min, max, step):88 self.min = min89 self.max = max...
LeJustePrython.py
Source:LeJustePrython.py
1price=1502#13print(price)4#25def ChangePrice():6 prix=3007 print(prix)8 9ChangePrice()10#311print(price)12#413def SayPrice():14 print(price)15 16SayPrice()17#518def ChangePriceTwo():19 global price 20 price = 3021 print(price)22 23print(price)24#625ChangePriceTwo()26#727print(price)28#829def ChangePriceThree(_price):30 _price = 7031 print(_price)32 33ChangePriceThree(price)34#935print(price)36#1037print(_price)38#1139def SayPriceTwo(_price):40 print(_price)41 42SayPriceTwo(price)43#1244SayPriceTwo(_price)45#1346def ReturnPrice(_price):47 return 1548print(ReturnPrice(price))49#1450print(price)51#1552price = ReturnPrice(1000)53print(price)54#1655def ReturnPriceTwo(_price):56 return _price + 557print(ReturnPriceTwo(price))58#1759print(ReturnPriceTwo(1000))60#1861print(price)62#1963price = ReturnPriceTwo(price)64print(price)65#2066price = ReturnPriceTwo(444719)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!