How to use press_enter method in Selene

Best Python code snippet using selene_python

UnHuggablesGame.py

Source:UnHuggablesGame.py Github

copy

Full Screen

...50 self.level_up()51 print_header(player)52 #print("You have gained {} experience!\n".format(xp_earned))53 print("Congratulations! you have leveled up! You are now level {}.\n".format(self.level))54 press_enter()55 else:56 print_header(player)57 print("You have gained {} experience!\n".format(xp_earned))58 press_enter()59 # Increase health and level value when leveling up60 def level_up(self):61 self.level += 162 self.health = 10 + round(self.level**3)63 64 def add_health(self, num):65 self.health += num66 def gain_item(self, item):67 self.items.append(item)68# Define class for Animal object69class Animal():70 71 # Initiate an animal class with a list of stats in the following order: [name, difficulty, friendship, irritability, skittishness, docility, experience, attack]72 # Stat explanations:73 # - name = the displayed name for the animal74 # - difficulty, 1-100, indicates the challenge level of the animal 75 # - friendship, -100 to 100, how receptive the animal is to the player's actions76 # - irritiability, 1-100, how likely an animal is to attack after failed interaction77 # - skittishness, 1-100, how likely an animal is to run after failed interaction78 # - docility, 1-100, how likely an animal is to remain after a failed interaction79 # - experience, >= 0, indicates how much experience is gained when hugging an animal80 #81 # When an action fails, the irritability, skittishness, and docility will be combined with a random number generator82 # to determine if the animal attacks, runs, or remains. These values can be adjusted based on interactions.83 # 84 def __init__(self, name):85 self.name = name86 #stat_list_titles = ["name", "difficulty", "friendship", "irritability", "skittishness", "docility", "experience", "attack"]87 self.actions = []88 self.base_stats = {}89 # loop_count = 090 #for title in stat_list_titles:91 # setattr(self, title, stats[loop_count])92 # loop_count += 193 self.art = ''94 def __repr__(self):95 out_string = ""96 97 out_string += "Name: " + self.name98 # out_string += "\nDifficulty: " + str(self.difficulty)99 # out_string += "\nFriendship: " + str(self.friendship)100 # out_string += "\nIrritability: " + str(self.irritability)101 # out_string += "\nSkittishness: " + str(self.skittishness)102 # out_string += "\nDocility: " + str(self.docility)103 # out_string += "\nExperience: " + str(self.experience)104 # out_string += "\nAttack: " + str(self.attack)105 out_string += "\n"106 return out_string107 108 def roll_new(self):109 # When rolling a new animal, the stats can vary +/- 25% of the base110 self.difficulty = round(self.base_stats["difficulty"] * (1 + (random.random()*0.5 - 0.25)))111 self.friendship = round(self.base_stats["friendship"] + (random.random()*15))112 self.irritability = round(self.base_stats["irritability"] * (1 + (random.random()*0.5 - 0.25))) 113 self.skittishness = round(self.base_stats["skittishness"] * (1 + (random.random()*0.5 - 0.25)))114 self.docility = round(self.base_stats["docility"] * (1 + (random.random()*0.5 - 0.25)))115 self.experience = self.difficulty116 self.attack = round(self.base_stats["attack"] * (1 + (random.random()*0.5 - 0.25)))117 118# Define environment objects to add flavor text to encounters119class Environment():120 def __init__(self, name, description):121 self.name = name122 self.description = description123class Action():124 def __init__(self, name, success_threshold = 50, success_msg = '', failure_msg = ''):125 self.name = name126 self.success_threshold = success_threshold127 self.success_msg = success_msg128 self.failure_msg = failure_msg129 130 def __repr__(self):131 return self.name132####################################################################################################################################133# This section is dedicated to creating action objects134####################################################################################################################################135pet_head = Action("Pet Head", 25, "Success! The {name} really liked getting pet on the head!\n", "Uh oh! It looks like the {name} is not in the mood for head pets!\n")136chin_scritch = Action("Scritch Chin", 40, "OOOHohoho, those was some gUUUd chin scritches. The {name} is pleased.\n", "The {name} isn't having it. It doesn't know you well enough to let you scritch its chin like that.\n")137belly_rubs = Action("Belly Rubs", 60, "Somebody loves a good belly rub! And that somebody is this {name}. They are VERY satisfied\n", "The {name} jumps back and recoils in anger. How DARE you touch its precious belly!\n")138butt_brush = Action ("Brush Butt", 50, "The {name} starts boogeying, leaning into the brush. They seem to be having a great butt time!\n", "That was awfully presumptuous! How would you like it if the {name} brushed YOUR butt? Well, you might like it, but they certainly didn't\n")139offer_treat = Action("Offer Treat", 10, "A bold move offering that {name} a treat, you could have lost a finger! Yet fortune favors the bold,\n the {name} graciously accepts it.\n", "The {name} is allergic to that treat! What are you, tring to poison it?!?\n")140polish_horns = Action("Polish Horns", 80, "Forget the proverbs, you just LITERALLY grabbed the {name} by the horns, and not only did you survive, but you left them with a mirror-like finish\n", "This was a bad idea. You knew this was a bad idea, but the {name} just confirmed that this was a bad idea.\n")141####################################################################################################################################142# This section is dedicated to creating animal objects143####################################################################################################################################144# For reference: stat_list_titles = ["name", "difficulty", "friendship", "irritability", "skittishness", "docility", "experience", "attack"]145animals_list = []146# Stats for Golden Retriever147golden_ret = Animal("Golden Retriever")148animals_list.append(golden_ret)149golden_ret.base_stats = {150 "difficulty": 10,151 "friendship": 15,152 "irritability": 10,153 "skittishness": 10,154 "docility": 70,155 "experience": 10,156 "attack": 3157 }158golden_ret.description = "Eyes bright and tail wagging, a GOLDEN RETRIEVER bounds toward you excitedly!\n"159golden_ret.actions = [offer_treat, pet_head, chin_scritch, belly_rubs]160# Stats for Bunny161bunny = Animal("Bunny")162animals_list.append(bunny)163bunny.base_stats = {164 "difficulty": 20,165 "friendship": 0,166 "irritability": 10,167 "skittishness": 80,168 "docility": 70,169 "experience": 20,170 "attack": 1171 }172bunny.description = "A Bunny is here!\n"173bunny.actions = [offer_treat, pet_head]174# Stats for house cat175cat = Animal("House Cat")176animals_list.append(cat)177cat.base_stats = {178 "difficulty": 30,179 "friendship": 0,180 "irritability": 50,181 "skittishness": 40,182 "docility": 70,183 "experience": 30,184 "attack": 4185 }186cat.description = "It's a House Cat!\n"187cat.actions = [offer_treat, pet_head, chin_scritch]188# Stats for sea turtle189turtle = Animal("Sea Turtle")190animals_list.append(turtle)191turtle.base_stats = {192 "difficulty": 40,193 "friendship": 0,194 "irritability": 20,195 "skittishness": 10,196 "docility": 80,197 "experience": 40,198 "attack": 10199 }200turtle.description = "A Sea Turtle turts around on the beach in front of you.\n"201turtle.actions = [pet_head, butt_brush]202# Stats for black bear203b_bear = Animal("Black Bear")204animals_list.append(b_bear)205b_bear.base_stats = {206 "difficulty": 50,207 "friendship": 0,208 "irritability": 70,209 "skittishness": 30,210 "docility": 40,211 "experience": 50,212 "attack": 20213 }214b_bear.description = "Which bear is best? A Black Bear! And now one is staring you in the face.\n"215b_bear.actions = [pet_head, chin_scritch]216# Stats for tiger217tiger = Animal("Tiger")218animals_list.append(tiger)219tiger.base_stats = {220 "difficulty": 60,221 "friendship": 0,222 "irritability": 80,223 "skittishness": 10,224 "docility": 30,225 "experience": 60,226 "attack": 30227 }228tiger.description = "Eeny Meeny Miney Moe - Hugging tigers is super dope. Now's your chance, because a Tiger is here! \n"229tiger.actions = [pet_head, chin_scritch]230# Stats for viper231viper = Animal("Viper")232animals_list.append(viper)233viper.base_stats = {234 "difficulty": 70,235 "friendship": 0,236 "irritability": 80,237 "skittishness": 30,238 "docility": 10,239 "experience": 70,240 "attack": 70241 }242viper.description = "A deadly Viper slithers out from underneath your credenza! But you, intrepid animal-hugger, know that even the non-cuddly animals need hugs!\n" 243viper.actions = [pet_head, chin_scritch]244# Stats for Minotaur245minotaur = Animal("Minotaur")246animals_list.append(minotaur)247minotaur.base_stats = {248 "difficulty": 80,249 "friendship": 0,250 "irritability": 90,251 "skittishness": 10,252 "docility": 20,253 "experience": 80,254 "attack": 50255 }256minotaur.description = "With a mighty roar, a MINOTAUR charges you from a nearby hedge maze! A less committed hugger would cower, but you know that all they need is a friend.\n"257minotaur.actions = [pet_head, chin_scritch, polish_horns]258# Stats for Introvert259introvert = Animal("Introvert")260animals_list.append(introvert)261introvert.base_stats = {262 "difficulty": 90,263 "friendship": 0,264 "irritability": 20,265 "skittishness": 80,266 "docility": 90,267 "experience": 90,268 "attack": 10269 }270introvert.description = "Before you sits one of the most challenging animals for even the most professional of huggers. The INTROVERT! Careful, I hear they can be grumpy!\n"271introvert.actions = [pet_head, chin_scritch]272###### Dragon stats are test stats to be changed later273dragon = Animal("Dragon")274animals_list.append(dragon)275dragon.base_stats = {276 "difficulty": 100,277 "friendship": -50,278 "irritability": 90,279 "skittishness": 90,280 "docility": 10,281 "experience": 100,282 "attack": 100283 }284dragon.description = "In front of you looms a massive D R A G O N!!! They like to cuddle, right?\n"285dragon.actions = [pet_head, chin_scritch, polish_horns]286####################################################################################################################################287# This section is dedicated to creating environment objects288####################################################################################################################################289environment_list = []290forest_desc = "You wander into a warm and dense forest. beams of sunlight pierce the canopy to fall gently on the ground." + \291 " The air smells of fresh pine. Before you, you see..."292forest = Environment('Forest', forest_desc)293environment_list.append(forest)294#################################################################################################################################295# Core game functions296#################################################################################################################################297def failed_action(animal):298 # Roll a random number for irritability, skittishness, and docility, the largest will determine the animals actions299 irrit = roll_number()+animal.irritability300 skitt = roll_number() + animal.skittishness301 doc = roll_number() + animal.docility302 print_header(player)303 if doc >= irrit and doc >= skitt:304 # Return to start of encounter305 print('The {} glares at you disapprovingly\n'.format(animal.name))306 press_enter()307 # If animal neither runs nor attacks, increase the irritability or skittishness308 flip_coin = round(random.random())309 if flip_coin == 0:310 animal.irritability += animal.difficulty/4311 else:312 animal.skittishness += animal.difficulty/4313 314 return "animal stays"315 elif skitt >= irrit:316 # Animal runs, draw new animal317 print('You scared the {}! It ran away.\n'.format(animal.name))318 press_enter()319 return "animal runs"320 else:321 #animal attacks322 print('You angered the {}. It ATTACKS! Doing {} damage\n'.format(animal.name, animal.attack))323 press_enter()324 player.add_health(1-animal.attack)325 return "animal stays"326# Function to process user commands other than Give Hug and Run Away (those are handled elsewhere)327def take_action(action, animal, affinity = 0):328 # Minimum score required for success:329 success_threshold = action.success_threshold 330 # Increase success threshold by animal difficulty331 success_threshold += animal.difficulty332 # Reduce threshold by friendship score and player level333 success_threshold -= animal.friendship/2334 success_threshold -= player.level*10335 num = roll_number()336 #print("Success Threshold = {}, you rolled: {}\n".format(success_threshold, num))337 if num >= success_threshold:338 print(action.success_msg.format(name = animal.name))339 # If the action is too easy, reduce the benefit.340 if (action.success_threshold + animal.difficulty)/2 + animal.friendship < action.success_threshold * 2:341 animal.friendship += (action.success_threshold + animal.difficulty)/2342 else:343 animal.friendship += (action.success_threshold + animal.difficulty)/5344 345 press_enter()346 return "animal stays"347 else:348 print(action.failure_msg.format(name = animal.name))349 animal.friendship -= (action.success_threshold + animal.difficulty)/2350 press_enter()351 return failed_action(animal)352# Give_hug is a special action that will either lead to success in the encounter or an attack from the animal.353# Threshold is defined as twice the animal difficulty minus the friendship level.354def give_hug(animal):355 # Hug should succeed 1 in 20 times before modifiers356 success_threshold = 95 + animal.difficulty - animal.friendship/2 - player.level * 10357 # print_header(player)358 num = roll_number()359 # num = 1000 # Set num to 1000 to force victory for testing purposes.360 #print_header(player)361 362 # If roll is successful increase player experience, check for player level up, end encounter363 if num >= success_threshold:364 365 # check_level_up(player)366 if animal.name == "Dragon":367 print_header(player)368 #print('Success Threshold = {}, you rolled: {}\n'.format(success_threshold, num))369 370 print("What?!?! No, that can't be! The Dragon is... HUGGING YOU BACK?!?!? This completely upends all of the conventional \nknowledge and scientific study on human-dragon interactions.\n")371 press_enter()372 return "win"373 else:374 print_header(player)375 #print('Success Threshold = {}, you rolled: {}\n'.format(success_threshold, num))376 print("The {} accepted your hug. You are now best buds!\n".format(animal.name))377 print("You gain {} experience.\n".format(animal.experience))378 press_enter()379 player.gain_experience(animal.experience)380 return "success"381 else: 382 player.add_health(-1*animal.attack)383 print_header(player)384 #print('Success Threshold = {}, you rolled: {}\n'.format(success_threshold, num))385 print("The {} is not ready to be hugged. It attacks! You take {} damage.\n".format(animal.name, animal.attack))386 animal.friendship -= (success_threshold)/2387 press_enter()388 return "animal stays"389def draw_animal(player):390 # Build weights list for each animal in animal list.391 # Compare player level * 10 to animal difficulty. Reduce likelihood by 1/2 for every 10 points of difference. Weight of 100 for 0 points.392 weight = []393 for item in animals_list:394 level_diff = abs(player.level * 10 - item.base_stats["difficulty"])395 weight.append((0.4**(level_diff/10))*100)396 #print(weight)397 #press_enter()398 return random.choices(animals_list, weights=weight)399def roll_number(num = 100):400 return round(random.random()*num)401# Function to print "Press enter to continue" prompt402def press_enter():403 input("Press enter to continue.\n")404 print("\033c")405 406# Function to determine if player died, returns boolean407def is_dead(player, animal):408 if player.health <= 0:409 print_header(player)410 print("You have {} health. Looks like that {} killed you. \n\nAt least you died doing what you loved - giving dangerous animals hugs.\n".format(player.health, animal.name))411 press_enter()412 return True413def print_header(player):414 print("\033c")415 print("--------------------------------------------------------------------------------------------------------------")416 print("|| {} Level: {} Experience: {} Current Health = {} ||".format(player.name, player.level, player.experience, player.health))417 print("--------------------------------------------------------------------------------------------------------------\n")418##################################################################################################################################419# Start of main game code420##################################################################################################################################421# Intiate game_over and game_won tags422game_over = False423game_won = False424### Startup ###425print("\033c")426print("""\427 000000000000000000000000000000000000000000000000000000000000000000000000000428 00000000000000000000000000000000000000000000000000000000000000000000000000000000000429 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000430 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000431000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000432000000000000 000000000000433000000000000 The UnHuggables!!! 000000000000434000000000000 000000000000435 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000436 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000437 00000000000000000000000000000000000000000000000000000000000000000000000000000000000438 000000000000000000000000000000000000000000000000000000000000000000000000000 439 440 441 """)442press_enter()443# Invite player to input name444player = Player()445# for i in range(5):446# print('.')447# time.sleep(1)448press_enter()449### Begin Encounters ###450while game_over == False:451 print_header(player)452 print("!!!!!!!!!!!!!!!!!!!! A NEW ANIMAL APPROACHES !!!!!!!!!!!!!!!!!!!!!!\n")453 press_enter()454 print_header(player)455 # Draw animal456 animal = draw_animal(player)[0]457 458 # Reset object stats for new animal459 animal.roll_new()460 # Reset encounter end flag461 encounter_over = False462 #initiate encounter counter - force a new loop if too many actions are taken463 encounter_counter = 0464 465 while encounter_over == False:466 # Increment counter467 encounter_counter += 1468 469 # Clear screen and print encounter description470 # print("\033c")471 # Print encounter description472 #473 # Print character status474 print_header(player)475 print(animal.description)476 print('On a scale of 1 to Friendly, you would rate this {} a {}.\n'.format(animal.name, str(round(animal.friendship))))477 # Print action options478 print('You feel that you can...')479 action_count = 0480 action_options = ''481 for item in animal.actions:482 action_count += 1483 action_options += str(action_count) + ". {} ".format(item.name)484 485 action_options += str(action_count + 1) + ". Give Hug " + str(action_count + 2) + ". RUN AWAY! \n"486 print(action_options)487 # Accept user selection with error handling for non-number or number out of range488 valid_input = False489 while not valid_input:490 try:491 action_choice = int(input("What do you do (enter number)? "))492 except:493 print("\nINVALID INPUT: Please enter a number between 1 and {}".format(action_count + 2))494 continue495 if action_choice > action_count + 2 or action_choice < 1:496 print("\nINVALID INPUT: Please enter a number between 1 and {}".format(action_count + 2))497 else:498 valid_input = True499 print("\033c")500 print_header(player)501 # while (not isnumber(action_choice)) or action_choice > action_count:502 # print("INVALID INPUT: Please enter a number between 1 and " + str(action_count))503 if action_choice == action_count + 1:504 action_result = give_hug(animal)505 506 # encounter_over = True507 # game_over = True508 # Execute Hug code509 elif action_choice == action_count + 2:510 print("Terrified of the vicious {}, you run. Barely escaping with your life".format(animal.name))511 input("\nPress enter to continue.\n")512 break513 else:514 action_result = take_action(animal.actions[action_choice-1], animal)515 516 517 if action_result == "animal runs" or action_result == "success":518 break519 elif action_result == 'win':520 game_won = True521 game_over = True522 break523 if encounter_counter > (round(random.random()*20) + 3):524 print_header(player)525 print("The {} has grown bored of your company. It chooses to move on to bigger and better things.\n".format(animal.name))526 press_enter()527 break528 if animal.friendship <= (-100 * player.level):529 print_header(player)530 print("Uh oh! Looks like you may have made an enemy. The {} attacks dealing you {} damage, before angrily storming away.\n".format(animal.name, animal.attack))531 print("The angered look in its eyes will live in your dreams forever.\n ")532 press_enter()533 if is_dead(player, animal):534 game_over = True535 break536 if is_dead(player, animal):537 game_over = True538 break539if game_won:540 print("Congratulations!!! Against all odds, you have managed to hug the dragon and come out alive. Truly, {}, you are a master of hugging! There is no more challenge left for you here.\n".format(player.name))541 press_enter()542 print("""543 *544 ***545 *****546 *******547 *********548 ***********549 *************550 *************************************************551 *******************************************552 ************ Victory ***********553 ************************** 554 ***********************555 ************ ************556 ********** **********557 ******** ********558 ****** ******559 **** ****560 ** **561 562 """)563else:564 print("\n\n\n")565 print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")566 print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Game Over XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")567 print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n")...

Full Screen

Full Screen

SendEmail.py

Source:SendEmail.py Github

copy

Full Screen

...66# buscar_propietario3 = "copy(nPr)"67 # pg.hotkey("alt","tab")68 # time.sleep(1)69 # pg.write(buscar_nacimiento1)70 # press_enter()71 # time.sleep(1)72 # pg.write(buscar_nacimiento2)73 # press_enter()74 # time.sleep(1)75 # pg.write(buscar_nacimiento3)76 # press_enter()77 # time.sleep(1)78 79 # pg.hotkey("alt","tab")80 # time.sleep(1)81 # pg.write(buscar_padre1)82 # press_enter()83 # time.sleep(1)84 # pg.write(buscar_padre2)85 # press_enter()86 # time.sleep(1)87 # pg.write(buscar_padre3)88 # press_enter()89 # time.sleep(1)90 # pg.hotkey("alt","tab")91 # time.sleep(1)92 # pg.write(buscar_madre1)93 # press_enter()94 # time.sleep(1)95 # pg.write(buscar_madre2)96 # press_enter()97 # time.sleep(1)98 # pg.write(buscar_madre3)99 # press_enter()100 # time.sleep(1)101 # pg.hotkey("alt","tab")102 # time.sleep(1)103 # pg.write(buscar_propietario1)104 # press_enter()105 # time.sleep(1)106 # pg.write(buscar_propietario2)107 # press_enter()108 # time.sleep(1.5)109 # pg.write(buscar_propietario3)110 # press_enter()...

Full Screen

Full Screen

test_todo_mvc.py

Source:test_todo_mvc.py Github

copy

Full Screen

...4def setup_module():5 browser.open('http://todomvc.com/examples/emberjs/')6 browser.driver.maximize_window()7def test_adding_and_completing_tasks():8 s('#new-todo').type('a').press_enter()9 s('#new-todo').type('b').press_enter()10 s('#new-todo').type('c').press_enter()11 ss('#todo-list>li').should(have.exact_texts('a', 'b', 'c'))12 s('#todo-list>li:nth-child(2) .toggle').click()13 s('#todo-list>li:nth-child(2)').should(have.css_class('completed'))14 s('#todo-list>li:nth-child(1)').should(have.no.css_class('completed'))15 s('#todo-list>li:nth-child(3)').should(have.no.css_class('completed'))16def teardown_module():...

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 Selene 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