def select_unassigned_variable(csp: list, assignment: set, method=0) -> variable: """ csp is the list of variables that are to be selected method is the method type in which they are selected 0:random #the default option 1:minimum-remaining value 2:minimum-remaining value together with degree """ if (method not in range(3)): return "method out of bounds" if (method == 0): y = rdint(0, len(csp) - 1) #rdint is inclusive, hence the -1 var = csp[y] while (var in assignment): y = rdint(0, len(csp) - 1) #rdint is inclusive, hence the -1 var = csp[y] return var elif (method == 1): #1:minimum-remaining value least_domain = math.inf low_var = None for var in csp: if (var not in assignment): dm_size = var.domain_size() if (dm_size == 0): return False if (dm_size < least_domain): least_domain = dm_size low_var = var return low_var elif (method == 2): #2:minimum-remaining value together with degree #the degree of the node works as a tie breaker, otherwise it works #just like minimum remaining value least_domain = math.inf low_var = None for var in csp: if (var not in assignment): dm_size = var.domain_size() if (dm_size == 0): return False if (dm_size < least_domain): least_domain = dm_size low_var = var elif (dm_size == least_domain and var.constraint_size() > low_var.constraint_size()): least_domain = dm_size low_var = var return low_var
def getVertifyImg(self): x_start = 2 y_start = 0 for i in range(self.num): x = x_start + i * int(self.width / (self.num)) y = rdint(y_start, int(self.height / 3)) self.drawText((x, y), self.get_random_char(), self.get_random_Color()) self.drawLine(3) self.drawPoint(60) return self.img
def dice_throw(): """Simulates two dice throws. :return: Random number between 2 and 12 """ return rdint(1, 6) + rdint(1, 6)
def rotate(self): deg = int(self.height / 3) # 旋转角度 self.img = self.img.rotate(rdint(0, deg), expand=0)
def get_random_xy(self): x = rdint(0, int(self.width)) y = rdint(0, int(self.height)) return x, y
def get_random_Color(self): c1 = rdint(50, 150) c2 = rdint(50, 150) c3 = rdint(50, 150) return c1, c2, c3
#!/usr/bin/python from random import randint as rdint nums = [(rdint(0, 100), rdint(0, 100)) for i in range(10)] print(nums) def pythagoras(lis): for i in range(len(lis)): m, n = lis[i] a = 2 * m * n b = m**2 - n**2 c = m**2 + n**2 print("m = %s, n= %s" % (m, n)) print("a = %s, b = %s, c = %s" % (a, b, c)) print("c^2 = a^2 + b^2") print("%s = %s + %s" % (c**2, a**2, b**2)) print("%s = %s" % (c**2, a**2 + b**2)) print("-" * 10) return print(pythagoras(nums))
''' Built In Modules São módulos que já vem por padrão no como uma biblioteca integrada do Python. ''' # https://docs.python.org/3/py-modindex.html # from random import randint as rdint print(rdint(0, 10))