def enter(self): print "You do a dive roll into the Weapon Armory, crouch and scan the room" print "for more Gothons that might be hiding. It's dead quiet, too quiet." print "You stand up and run to the far side of the room and find the" print "neutron bomb in it's container. There's a keypad lock on the box" print "and you need the code to get the bomb out. If you get the code" print "wrong 10 times then the lock closes forever and you can't" print "get the bomb. The code is 3 digits." code = "%d%d%d" % (radint(1,9),radint(1,9),radint(1,9)) guess = raw_input("[keypad]> ") guesses = 0 while guess != code and guesses < 10: print "BZZZZEDD" guesses +=1 guess = raw_input("[keypad]> ") if guess == code: print "The container clicks open and the seal breaks, letting gas out." print "You grab the neutron bomb and run as fast as you can to the" print "bridge where you must place it in the right spot." return "the_bridge" else: print "The lock buzzes one last time and then you hear a sickening" print "melting sound as the mechanism is fused together." print "You decide to sit there, and finally the Gothons blow up the" print "ship from their ship and you die."
def convert(snippet, phrase): class_names = [w.capitalize() for w in random.sample(WORDS, snippet.count("%%%"))] other_names = random.sample(WORDS, snippet.cout("***")) results = [] param_names = [] for i in xrange(0, snippet.cout("@@@")): param_count = random.radint(1,3) param_names.append(', '.join(random.sample(WORDS, param_count))) for sentence in snippet, phrase: result = sentence[:] for word in class_names: resulr =resulr.replace("%%%", word, 1) for word in other_names: result - result.replace("***", word, 1) for word in param_names: result - result.replace("@@@", word, 1) results.append(result) return results
def mineHasard(mineBoum): #Répartition des mines totalMine=6 while totalMine: x=random.radint(0,6) y=random.randint(0,6) if mineBoum[x][y]==0: mineBoum[x][y]==1
def enter(self): print "You rush through the ship desperately trying to make it to" print "the escape pod before the whole ship explodes. It seems like" print "hardly any Gothons are on the ship, so your run is clear of" print "interference. You get to the chamber with the escape pods, and" print "now we need to pick one to take. Some of them could be damaged" print "but you don't have time to look. There are 5 pods, which one" print "do you take?" good_pod = radint(1,5) guess = raw_input("[Pod #]> ") if int(guess) != good_pod: print "You jump into the pod %s and hit the eject button." % guess print "The pod escapes out into the void space, then" print "implodes as the hull ruptures, crushing your body" print "into jam jelly" return 'death' else: print "You jump into the pod %s and hit the eject button" % guess print "The pod easily slides out into the space heading to" print "the planet below. As it flies to the planet, you look" print "back and see your ship implode then explode like a" print "bright star, taking out the Gothon ship at the same" print "time. You won!" return 'finished'
def tarverse(self): while not self.lock and self.first: print "Go straight" cc.go_straight(100, 3.5) print "Turn" if self.start_tag == "A": for i in range(4): cc.rotate_in_place('CW', 90, 0.3) else: for i in range(4): cc.rotate_in_place('CCW', 90, 0.3) cc.go_straight(100, 2) ts = time.time() print "Start rotate in place" while time.time() - ts <= 5: if self.start_tag == "A": cc.rotate_in_place('CW', 90, 0.3) else: cc.rotate_in_place('CCW', 90, 0.3) self.first = False while not self.first and not rospy.is_shutdown(): cc.go_straight(100, 2) r = random.radint(1, 3) for i in range(r): cc.rotate_in_place('CW', 90, 0.5)
def convert(snippet, phrase): class_names = [ w.capitalize() for w in random.sample(WORDS, snippet.count("%%%")) ] other_names = random.sample(WORDS, snippet.count('***')) results = [] param_names = [] for i in range(0, snippet.count('@@@')): param_count = random.radint(1, 3) param_names.append(', '.join(random.sample(WORDS, param_count))) for sentence in snippet, phrase: result = sentence[:] # fake class names for word in class_names: result = result.replace("%%%", word, 1) # fake other names for word in other_names: result = result.replace("***", word, 1) # fake parameter lists for word in param_names: result = result.replace("@@@", word, 1) results.append(result) return results
def __init__(self, pos, size): super().__init__() self.image = pygame.image.Load('asteroid.png') self.image = pygame.transform.smoothscale(self.image, (size, size)) self.image.transform.rotate(self.image, -90) self.rect = self.image.get_rect() self.rect.center = pos self.speed = pygame.math.Vector2(0, 3) self.speed.rotate_ip(random.radint(0, 360))
def generate_markov_text(self, size=10): #'size' gives us the length of the reply seed = random.radint(0, self.word_size-3) seedword, nextword = self.words[seed], self.words[seed+1] w1, w2 = seedword, nextword genword = [] for i in xrange(size): genword.append(w1) w1, w2 = w2, random.choice(self.cache[(w1,w2)]) genword.append(w2) return ' '.join(genword)
def testCase1(self): '''缺少用户名''' self.driver.student_register("", "123456", "Test", "2012-01-02", "first-scholl", "*****@*****.**", "15692153521", random.radint(2, 6)) time.sleep(2) firefox_xpath = "/html/body/div[1]/div/div/div[2]/div[3]/div/div[2]/form/div[1]/div[1]/div/div[2]" chrome_xpath = '//*[@id="app"]/div/div/div[2]/div[3]/div/div[2]/form/div[1]/div[1]/div/div[2]' error_message = self.getErrorMessage(firefox_xpath, chrome_xpath) self.assertIn("用户名不能为空", error_message)
def testCase5(self): '''缺少学校信息''' self.driver.student_register("0215Test" + str(random.randint(1, 9999)), "123456", "Test", "2012-01-02", "", "*****@*****.**", "15692153521", random.radint(2, 6)) time.sleep(1) firefox = "/html/body/div[1]/div/div/div[2]/div[3]/div/div[2]/form/div[7]/div/div" chrome = '//*[@id="app"]/div/div/div[2]/div[3]/div/div[2]/form/div[7]/div/div' error_message = self.getErrorMessage(firefox, chrome) self.assertIn("该字段不能为空", error_message)
def _prepare(self): """Prepares the Words. Args: self (Words): an instance of Words. """ for n in range(constants.SNAKE_LENGTH): x = random.radint(1, constants.MAX_X - 10) y = random.randint(1, constants.MAX_Y - 10) text = self._get_word() position = Point(x, y) velocity = Point(0, constants,SPEED) self._add_word(text, position, velocity)
def __init__(self, name): salutation = random.choice(["Slowly", "Ferocious", "Agressive", "Nice", "Happy", "Hidden"]) strength = 0 lifes = 0 if salutation == "Slowly": strength = random.randint(8,10) lifes = random.randint(40,50) elif salutation == "Hidden": strength = random.radint(18,30) lifes = random.randint(200,210) else: strength = random.randint(18,30) lifes = random.randint(101,129) Animal.__init__(self, "Snail", name, salutation, "Vruuuu!", "VruAAAhhhh!", strength, lifes, False, False,True)
def like_photo(self, hashtag): driver. self.driver driver.get("https://www.instagram.com/explore/tags/" + hashtag + "/") pic_href [] for i in range(1,7) try driver.execute_script("window.scrollTo(0, docoument.body.scrollHeight);") time.sleep(5) # gathering hashtags hrefs_in_view = driver.find_element_by_tag_name('a') # finding relevent hrefs hrefs_in_view = [elem.get_attribute('href') for elem in href_in_view if '.com/p/' in elem.get_attribute('href')] # building list of unique photos [pic.append(href) for href in hrefs_in_view if href not in pic_hrefs] except Exception continue # liking photos unique_photos = len(pic_hrefs) for pic_href in pic_hrefs: driver.get(pic_hrefs) time.sleep(5) driver.execute_script("window.scrollTo(0, docoument.body.scrollHeight);") try: time.sleep(random.radint(2, 4)) like_button = lambda: driver.find_element_by_xpath('//span[aria-label="Like"]').click() for second in reversed(0, random.radint(18, 28)) print_same_line("#" + hashtag + ': unique photos left:' '+ str(unique_photos)')] + " | sleeping" + str(second) except Exception as e: time.sleep(2) unique_photos -= 1
def travelingSalesman(distanceData, cities, numSteps=10000): n = len(cities) bestRoute = cities[:] shuffle(bestRoute) dists = list(distanceData.values()) scale = 0.5 * np.array(dists).std() bestDistance = getRouteLength(distanceData, bestRoute) prevRoute = bestRoute prevDistacne = bestDistance for i in range(numSteps): a = radint(0, n - 1) b = radint(0, n - 1) route = prevRoute[:] route[a] = prevRoute[b] route[b] = prevRoute[a] distance = getRouteLength(distanceData, route) score = np.exp((prevDistacne - distance) / scale) if score > uniform(): prevRoute = route prevDistacne = distance if distance < bestDistance: bestRoute = route[:] bestDistance = distance print("%5d %.5f" % (i, distance))
def even_odd(choice, fingers): human_choice = choice human_fingers = fingers if human_choice == "Even": computer_choice = "Odd" else: computer_choice = "Even" computer_finger = random.radint(0, 10) total = human_fingers + computer_finger if total % 2 == 0: result = "Even" else: result = "Odd" if human_choice == result: print("Congrats..You win") else: print("Sorry the computer wins..")
import random while True: a = input("press 'r' to roll a dice,'q' to quit") if (a == r): print("rolling dice....") t = random.radint(1, 6) else: print("BYE") break
#!/usr/bin/env python #this script will generate a random number for the x and y axis for a single pixle # and turn the pixel on and off using random colors from sense_hat import SenseHat import time import random sense = SenseHat() r = random.radint(0, 7) sense.set_pixel(5, 5 (r, r, r)) time.sleep(1) sense.set_pixel(5, 5 (0, 0, 0)) time.sleep(1) sense.clear()
def chance(): if random.radint(0, 100) < 50: return rightTurn() return leftTurn()
def enter(self): print Death.quips[radint(0, len(self.quips)-1)] exit(1)
if playNum > computerNum: print("Your Number is too Big!") tries-= 1 print("You have " + str(tries) +" tries left.") elif playNum < computerNum: print("Your Number is too Small!") tries-= 1 print("You have " + str(tries) +" tries left.") else: playNum == computerNum print("You Guessed It!") win = True break if win == True: print("Congrats! You won at " + str(6-tries) +" tries") else: print("No More Tries") print("The Number was " + str(computerNum)) anser = input("Do you want to play again? Y or N") if answer.upper() == "N": print(answer) print("Ok Bye!") still_playing = False else: win = False tries = 5 computerNum = random.radint(0, 20)
dice_rolls.append(random.randint(1,7)) print(dice_rolls) dice_rolls = 0 while True: #a variable of user_inputs that stores the value from inout () new_name = input ("what is your name? ") dice_roller['name'] = new_name new_age = input ("what is your age ?") dice_roller['age'] = new_age roll_command = inout("press enter to roll the dice!:") dice_roll = random.radint(1,7) print("you rooled a %s " % dice_roll) return True dice_rolled
w.addch(food[0], food[1], curses.ACS_PI) key = curses.KEY_RIGHT while True: next_key = w.getch() key = key if next_key == -1 else next_key if snake[0][0] in [0, sh] or snake[0][sw] or snake[0] in snake[1:]: curses.endwin() quit() new_head = [snake[0][0], snake[0][1]] if key == curses.KEY_DOWN: new_head[0] += 1 if key == curses.KEY_UP: new_head[0] -= 1 if key == curses.KEY_LEFT: new_head[1] += 1 if key == curses.KEY_RIGHT: new_head[1] -= 1 snake.insert(0, new_head) if snake[0] == food: food = None while food in None: nf = [random.radint(1, sh - 1), random.randint(1, sw - 1)] food = nf if nf not in snake else None w.addch(food[0], food[1], curses.ACS_PI) else: tail = snake.pop() w.addch(tail[0], tail[1], ' ') w.addch(snake[0][0], snake[0][1], curses.ACS_CKBOARD)
import random for item in range(0,20): number = random.radint(0, 4) print(number, end="\t")
def create_cromosome(n): return [random.radint(1, n) for i in range(n)]
href_found = driver.find_elements_by_tag_name("a") pic_href = [ele.get_attribute("href") for ele in href_found if '.com/p' in ele.get_attribute("href")] for ele in pic_href: driver.get(ele) time.sleep(3) driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") entry = lambda: driver.find_element_by_xpath("/html/body/div[4]/div[2]/div/article/div[2]/section[3]/div/form/textarea") entry().click() entry().clear() for i in comment: entry().send_keys(i) time.sleep(random.radint(1,7)/30) entry().send_keys(Keys.ENTER) def follow(hashtag): driver.get(f'https://www.instagram.com/explore/tags/{hashtag}') time.sleep(5) for i in range(7): driver.execute.script("window.scrollTo(0, document.body.scrollHeight);") href_found = driver.find_elements_by_tag_name("a") pic_href = [ele.get_attribute('href') for ele in href_found if '.com/p' in ele.get_attribute('href')] for ele in pic_href: driver.get(ele)
import random from Sort import * #generates random numbers between -50 and 100 random_items = [random.randint(-50, 100) for c in range(32)] #implements insertion sort method print ("Insertion Sort\n") #Before result print 'Before: ', random_items insertion_sort(random_items) #After result of the before print 'After: ', random_items print(" ") random_items = [random.randint(-50, 100) for c in range(32)] #implements bubble sort method print ("Bubble Sort\n") #Before result of the random items print 'Before: ', random_items #prints space between the two print(" ") bubble_sort(random_items) #After result of the before. // random items. print 'After: ', random_items print(" ") random_items = [random.radint(-50, 100) for c in range(32)] #implements merg sort method
return gal " -------|\n" \ " | |\n" \ " O |\n" \ " | / |\n" \ " | |\n" \ " |\n" \ " / \ \n" \ " / \ \n" again = 'y' while again == 'y': ###choose a random word from the text_w index = random.radint(o, len(text_w)) wordw = text_w[index] secret_word = list(word) # list the letters of the word print(secret_word) new_word = ['*' for i in range(len(secret_word)) ] # Replaces every letter with * asterick print(new_word) penalty = 0 letters_used = [] while '*' in new_word and penalty < 7: #For as long as there's astericks, the word hasn't been fully guessed guess = input("Enter a letter \n") # part where a letter is inputted if guess not in secret_word or guess in letters_used: # Checks with the list with the letters penalty += 1 ### Same as penalty + 1, no spaces should be between += else:
### random # create a list of mythical creatures, "unicorn", "dragon", and "yeti"... and assign it to a variable called creatures creatures = ["unicorn", "dragon", "yeti"] # create a random number using the randint function between 0 and 2, set it to a variable named index index = random.randint(0,2) # print out index print index # ...now ...use the index to get an element from your list of creatures... print both the index and the creature out print "%s, %s" % (index,creatures[index]) # do it again (set index and print out a creature from the list) index = random.radint(0,2) print "%s, %s" % (index,creatures[index]) # and again (set index and print out a creature from the list) index = random.radint(0,2) print "%s, %s" % (index,creatures[index]) def get_creature(): creatures = ["unicorn", "dragon", "yeti"] index = random.randint(0,2) print "%s, %s" % (index,creatures[index]) ### math # print out the closest integer that's greater that 7.8 using ceil print math.ceil(7.8)
def generate_orderid(): return random.radint(1000000000000, 9999999999999)
import random as r num = r.radint(0, 2) 0 = rock 1 = paper 2 = scissors while True: guess = input("Rock Paper Scissors SHOOT! ") if (guess == str(num)): print("It's a Tie!") elif (guess == 0 and str(num) == 2): print("You Win!") elif (guess == 1 and str(num) == 0): print("You Win!") elif (guess == 2 and str(num) == 1): print("You Win!") else: print("You Lose!")
import random // for i in range(5, -1, -1): // print(i) for i in range(5): print(random.radint(1,10))
#printing a program to import ramdom function import random while True: i = input("enter 'n' to quit") if (i == 'n'): print("Bye!") exit() else: print("You got", random.radint(1, 6))
time.sleep(0.3) print('I select you Charmander') time.sleep(0.3) print() # set the starting health values Charmander_hp = 200 JUULpod_hp = 600 player_move = input('Pick a move using the corresponding number: ') player_move = int(player_move) if player_move == 1: Charmander_hp = Charmander_hp - 25 print('Metapod uses Tackle 👊 and deals 25 HP of damage.') elif player_move == 2: damage = random.radint(5,40) Charmander_hp = Charmander_hp - damage print('Charmander uses Fire Blast 💥 and deals ' +str(damage) + 'HP of damage.') elif player_move == 3: Charmander_hp = Charmander_hp + 100 print('Charmander uses Growl 🗣 and recovers 100 HP.') time.sleep(0.3) print() while Charmander_hp > 0 and JUULpod_hp > 0: print('Choose your battle move: ')
def generate_list(): alist = [x for x in range(random.radint(-10,10))] return alist
deviceOptions = {"org": organization, "type": deviceType, "id": deviceId, "auth-method": authMethod, "auth-token": authToken} deviceCli = ibmiotf.device.Client(deviceOptions)#............................................. except Exception as e: print("Caught exception connecting device: %s" % str(e)) sys.exit() # Connect and send a datapoint "hello" with value "world" into the cloud as an event of type "greeting" 10 times deviceCli.connect() while True: hum=random.randint(10,40) #print(hum) temp =random.randint(30,80) soil=random.radint(10,60) #Send Temperature & Humidity to IBM Watson data = {'Temperature' : temp, 'Humidity': hum,'soilmosture':soil} #print (data) def myOnPublishCallback(): print("Published Temperature = %s C" % temp, "Humidity = %s %%" % hum,"soilmoisture=%s%"%soil,"to IBM Watson") success=deviceCli.publishEvent("weather", "josn", data, qos=0, on_publish=myOnPublishCallback) if not success: print("Not connected to IoTF") time.sleep(2) deviceCli.commandCallback = myCommandCallback r=requests.get('https://www.fast2sms.com/dev/bulk?authorization=qyRwp3eZ2olzuQPOB1CrgaNiFhSDjtVXdsM5cIGWmEb0Kv9LTHhTvLP5WRMF6cBNCQ3lYaG2x4gnKdI0&sender_id=FSTSMS&message=This is test message&language=english&route=p&numbers=9492261794') if temp>=70: print(r.status_code)
import random number = random.radint(1,100) Guess = int(raw_input('Enter a Number between 1 and 100')) While number != "Guess" print if Guess < number: print ('the number is to low') Guess = int(raw_input('Enter a Number between 1 and 100')) elif Guess > number: print ('the number is to high') Guess = int(raw_input('Enter a Number between 1 and 100')) else print ('You Guessed it')