def r(name): im = Image.open(name) os.remove(name) r = (ra(2, 10), ra(2, 10), ra(20, 150)) print(r) dst_grid = griddify(shape_to_rect(im.size), r[0], r[1]) src_grid = distort_grid(dst_grid, r[2]) mesh = grid_to_mesh(src_grid, dst_grid) im = im.transform(im.size, Image.MESH, mesh) im.save(name)
def luhn(): """ Алгоритм Луна использует простое правило вычисления контрольной суммы для проверки идентификационных номеров, таких как номера пластиковых карт. Алгоритм определяет ошибки ввода одной неправильной цифры, а также почти все перестановки соседних цифр, за исключением перестановки 09-90 или обратной 90-09. В данном случае в задании было указано генерировать номера карт с 400000 + случайные цифры(длина номера карты 16), которые должны проходить проверку алгоритмом Луна. """ card = str("400000" + "".join([str(ra(0, 9)) for _ in range(10)])) card = [int(i) for i in card] rest = card[:len(card) - 1] for i in range(len(rest)): if i % 2 == 0: rest[i] = rest[i] * 2 for i in range(len(rest)): if rest[i] > 9: rest[i] = rest[i] - 9 s = sum(rest) last_digit = 0 if s % 10 == 0: last_digit = 0 else: last_digit = 10 - (s % 10) valid = card[:len(card) - 1] valid.append(last_digit) valid = [str(i) for i in valid] return "".join(valid)
def newlocus(self): self.resetValues() self.c1 = Complex(ra(-16,16),ra(-16,16)) self.locus_type = ra(1,3) if self.locus_type == 1: self.radius = ra(1,10) elif self.locus_type == 2: self.c1 = Complex(ra(-12,12),ra(-12,12)) self.rand = ra(-8,8) while self.rand == 0: self.rand = ra(-8,8) self.theta = np.pi / self.rand elif self.locus_type == 3: self.c2 = Complex(ra(-16,16),ra(-16,16)) self.locus_type_text = lociTypeDecider(self.locus_type)
def fileName(): global names file = open("Footer.txt") data = file.read().split('\n')[:-1] file.close() randomCollection = [] count = 1 for i in data: string = i.split(",") year = findYear(string[-1]) month = findMonth(string[-2]) date = findDate(string[-2]) # print(count," | ",date, month, year) count += 1 random = ra(100001,999999) while(random in randomCollection): random = ra(100001,999999) names.append('t' + year + month + date + str(random))
def sek(out, m): i = n.array(I.open(out)) s = bee(ord(m)) b = 2 for _ in range(Z): while True: r, g = ch(s) if ra(False, True) == False: r += n.random.normal(scale=16) if r < False or r >= 128: continue else: g += n.random.normal(scale=16) if g < False or g >= 128: continue r = int(r) g = int(g) i[r][g][b] |= True break return i
def play_guess_the_number(): print("Please enter the minimum value:") i=int(input()) print("Please enter the maximum value:") j=int(input()) while(j<=i): print("The maximum cannot be lower than or equal to the minimum. Please choose a different maximum:") j=int(input()) n=ra(i,j,1) print("I am thinking of a number between {} and {}. Can you guess what it is?".format(i,j)) while(1==1): i=int(input()) if n==i: print("Congratulations! You guessed my number!") break elif n>i: print("Your guess is too low!") else: print("You guess is too high!") print("Try again:")
def create_account(self): card_number = self.luhn() pin = "".join([str(ra(0, 9)) for _ in range(4)]) self.db.db_add_account(card_number, pin) return card_number, pin
def rand_int(): return int(ma.floor(ra()*10))
pygame.quit() raise SystemExit painettu = pygame.key.get_pressed() #täällä kaikki painetut näppäimet x_info = painettu[pygame.K_RIGHT] - painettu[pygame.K_LEFT] if painettu[pygame.K_UP] and ground_touch == True: yvel = -21 + difficulty ground_touch = False xvel += x_info if points >= seur: #luodaan uusi taso seur = points + 100 tyyppi = 0 if turn == 1: tyyppi = ra(0, 3) else: tyyppi = ra(0, 1) if tyyppi == 2: #punainen, aiheuttaa mahdottomia kohtia, jos liian leveää platwidth = ra(60, 150) else: platwidth = ra(60, 300) left = ra(15, 585 - platwidth) if tyyppi != 3: items.append(platform(left, left + platwidth, -points, typ=tyyppi)) turn *= -1 if ground_touch == True: yvel = 0 y = points + touch_y - 20 else:
import numpy as np from sklearn import datasets, linear_model from random import randint as ra import matplotlib.pyplot as plt # 定义训练数据 x = np.array([[ ra(0, 99) * 0.01, ra(0, 99) * 0.01, ra(0, 99) * 0.01, ra(0, 99) * 0.01, ra(0, 99) * 0.01 ], [ ra(0, 99) * 0.01, ra(0, 99) * 0.01, ra(0, 99) * 0.01, ra(0, 99) * 0.01, ra(0, 99) * 0.01 ], [ ra(0, 99) * 0.01, ra(0, 99) * 0.01, ra(0, 99) * 0.01, ra(0, 99) * 0.01, ra(0, 99) * 0.01 ], [ ra(0, 99) * 0.01, ra(0, 99) * 0.01, ra(0, 99) * 0.01, ra(0, 99) * 0.01,
for i in range(len(board)): if board[i] == ' ': tBoard = dc(board) tBoard[i] = player score, move = bestMove(tBoard, opponent) results.append((score, i)) if player == 'O': return max(results) else: return min(results) """ Testing """ while True: print() p = ra(0, 1) print("Index layout") printBoard([1, 2, 3, 4, 5, 6, 7, 8, 9]) board = initializeBoard() if p == 0: print("Computer plays first ") while not isWin(board, "O") and not isWin(board, "O") and not isDraw(board): bestmove = bestMove(board, "O")[1] board[bestmove] = "O" printBoard(board) if isWin(board, "O"): print("Computer wins") break i = int(input("Enter your move: ")) - 1 board[i] = "X"