def mutation(self, taxa: float = 1.0, randomize: bool = False): assert taxa > 0.0 or taxa <= 1.0 if self.cromossomo is None or len(self.cromossomo) <= 0: return from random import random as r, randint as r_int qtd = int(round(taxa * len(self.cromossomo))) for g in range(qtd): index = r_int(0, len(self.cromossomo) - 1) key = self._keys[index] var = (r() * (-1 if(r_int(0, 1)) else 1)) if randomize: self.cromossomo[key] = var else: value = self.cromossomo[key] new = ((value**2) * var * taxa) if (value + new) > 1.0: value = value - new elif (value - new) < -1.0: value = value + new else: value = value + new if value > 1.0: value = 1.0 if value < -1.0: value = -1.0 self.cromossomo[key] = value
def __init__(self, card_number, cardholder, expiry_month, expiry_year, cvv): self.first_name = f_names[r_int(0, len(f_names) - 1)] self.last_name = l_names[r_int(0, len(l_names) - 1)] self.email = self.generate_email(self.first_name, self.last_name) (self.token, self.card) = self.get_shopify_payment_token(card_number, cardholder, expiry_month, expiry_year, cvv) """
#!/usr/bin/python # -*- coding: utf-8 -*- from random import randint as r_int # generates a random number # in inclusive list from 0 to 10 n = r_int(0, 10) print("Hint: number is between 0 to 10 including 0 and 10\n") while True: usr = int(raw_input("Guess a number: ")) # Make sure user got the hint if usr <= 10 and usr >= 0: # if correct if usr == n: print("That's a correct guess!\nYou got it!\n") break # brings user closer to answer elif usr < n: print("Try a bigger num!") else: print("Try a smaller num!") else: print("Pls read the hint!")
# +:+ +:+ +:+ # # By: plam <*****@*****.**> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/03/23 15:58:48 by plam #+# #+# # # Updated: 2020/03/24 17:11:44 by plam ### ########.fr # # # # **************************************************************************** # import sys import random from sys import argv as av from random import randint as r_int inp = 0 cnt = 0 answer = r_int(1, 99) print("This is an interactive guessing game!") print( "You have to enter a number between 1 and 99 to find out the secret number." ) print("Type 'exit' to end the game.") print("Good luck!\n") while inp != answer: inp = input("What's your guess between 1 and 99?\n") if not inp.isdigit() and inp != "exit": print("That's not a number.") elif inp == "exit": print("Goodbye!") sys.exit(1) else: inp = int(inp)
# print(random_number, random_letter, letters) # ------------------------------------------------ # # import SPECIFIC attributes from a module # keywords: from / import # from <MODULE_NAME> import <ATTRIBUTE_1>, <ATTRIBUTE_2>, ... from string import ascii_letters # only import ascii_letters from string module from random import randint, choice # only import randint() and choice() from random letters = ascii_letters # shorten variable name random_number = randint(1, 100) # don't need random.randint() anymore random_letter = choice(letters) # print(random_number, random_letter, letters) # ------------------------------------------------- # # import SPECIFIC attributes from a module # and change their variable name # keywords: from / import / as # from <MODULE_NAME> import <ATTRIBUTE_NAME> as <VARIABLE_NAME> from string import ascii_letters as letters from random import randint as r_int, choice as r_ch random_number = r_int(1, 100) random_letter = r_ch(letters) # print(random_number, random_letter, letters)
def gen(): return str(r_int(1, pow(64, 10)))
class person: def __init__(self, card_number, cardholder, expiry_month, expiry_year, cvv): self.first_name = f_names[r_int(0, len(f_names) - 1)] self.last_name = l_names[r_int(0, len(l_names) - 1)] self.email = self.generate_email(self.first_name, self.last_name) (self.token, self.card) = self.get_shopify_payment_token(card_number, cardholder, expiry_month, expiry_year, cvv) """ self.phone_number = phone self.city = "charlotte" self.address = address self.postal_code = mail_code self.state = "North Carlolina" Self.Country = "United States" """ #generate payment token in advanced to save time. def get_shopify_payment_token(self, card_number, cardholder, expiry_month, expiry_year, cvv): link = "https://elb.deposit.shopifycs.com/sessions" payload = { "credit_card": { "number": card_number, "name": cardholder, "month": expiry_month, "year": expiry_year, "verification_value": cvv } } r = requests.post(link, json=payload, verify=False) payment_token = json.loads(r.text)["id"] return (payment_token, payload['credit_card']) def generate_email(self, fname, lname): case = r_int(0, 3) if (case == 0): username = fname + transitions[r_int(0, len(transitions) - 1)] + lname elif (case == 1): username = fname[0] + lname + transitions[r_int( 0, len(transitions) - 1)] + str(r_int(0, 99)) elif (case == 2): username = fname + lname + str(r_int(0, 99)) else: date = r_int(19, 20) if (date == 20): date = str(date) + "0" + str(r_int(0, 6)) else: date = str(date) + str(r_int(84, 99)) username = fname + transitions[r_int(0, len(transitions) - 1)] + date if (" " in username): username.replace(" ", transitions[r_int(0, len(transitions) - 1)]) return username + email_extensions[r_int(0, len(email_extensions) - 1)]