def on_update(self, delta_time): bubble(self.bars)
import sorting import timeit data = [1, 8, 3, 5, 6, 9, 2, 4] start_time = timeit.default_timer() sorting.bubble(data) end_time = timeit.default_timer() print('Bubble Sort : ', '%.15f' % (end_time - start_time)) start_time = timeit.default_timer() sorting.bucket(data) end_time = timeit.default_timer() print('Bucket Sort : ', '%.15f' % (end_time - start_time)) start_time = timeit.default_timer() sorting.comb(data) end_time = timeit.default_timer() print('Comb Sort : ', '%.15f' % (end_time - start_time)) start_time = timeit.default_timer() sorting.counting(data) end_time = timeit.default_timer() print('Counting Sort : ', '%.15f' % (end_time - start_time)) start_time = timeit.default_timer() sorting.maxheap(data) end_time = timeit.default_timer() print('Max Heap Sort : ', '%.15f' % (end_time - start_time)) start_time = timeit.default_timer()
import sorting print sorting.qsort([10,9,8,7,6,5,4,3,2,1]) print sorting.qsort([1,2,3,4,5,6,7,8,9,10]) print sorting.qsort([6,7,8,9,10,1,2,3,4,5]) print sorting.select([10,9,8,7,6,5,4,3,2,1]) print sorting.select([1,2,3,4,5,6,7,8,9,10]) print sorting.select([6,7,8,9,10,1,2,3,4,5]) print sorting.bubble([10,9,8,7,6,5,4,3,2,1]) print sorting.bubble([1,2,3,4,5,6,7,8,9,10]) print sorting.bubble([6,7,8,9,10,1,2,3,4,5])
def test_normalList(self): sorting.bubble(self.nums) self.assertEqual(self.nums, self.expected)
def random_object_generator(self,nr): self.objects=[] self.obstacles=[] self.Glist=self.create_grid() rand_obst=randint(2,3) while rand_obst!=0: rand_dimension=randint(45,60) i=randint(0,len(self.Glist)-1) pos=list(self.Glist)[i] rand_x=pos[0] rand_y=pos[1] ok=1 #checking if the position is available for x in range(rand_x-60,rand_x+61,30): for y in range(rand_y-60,rand_y+61,30): if (x,y)in self.Glist and self.Glist[(x,y)]==True: pass else: ok=0 if ok: for x in range(rand_x-60,rand_x+61,30): for y in range(rand_y-60,rand_y+61,30): self.Glist=self.occupy_grid(x,y) ob4=Circle(rand_x,rand_y,rand_dimension,self.screen,self.yellow) rand_obst=rand_obst-1 self.obstacles.append(ob4) while nr>0: rand_shape=randint(1,3) rand_colour=randint(1,3) colours={1:self.red,2:self.blue,3:self.green} if rand_colour==1: price=randint(4,6) elif rand_colour==2: price=randint(7,9) elif rand_colour==3: price=randint(1,3) j=randint(0,len(self.Glist)-1) pos=list(self.Glist)[j] rand_x=pos[0] rand_y=pos[1] if rand_shape==1: ok=1 for x in range(rand_x,rand_x+31,30): for y in range(rand_y,rand_y+31,30): if (x,y)in self.Glist and self.Glist[(x,y)]==True: pass else: ok=0 if ok: for x in range(rand_x,rand_x+31,30): for y in range(rand_y,rand_y+31,30): self.Glist=self.occupy_grid(x,y) ob1=Square(rand_x,rand_y,price,45,self.screen,colours[rand_colour]) self.objects.append(ob1) nr=nr-1 elif rand_shape==2: ok=1 for x in range(rand_x,rand_x+31,30): for y in range(rand_y,rand_y+31,30): if (x,y)in self.Glist and self.Glist[(x,y)]==True: pass else: ok=0 if ok: for x in range(rand_x,rand_x+31,30): for y in range(rand_y,rand_y+31,30): self.Glist=self.occupy_grid(x,y) ob2=Triangle(rand_x,rand_y,price,45,self.screen,colours[rand_colour]) self.objects.append(ob2) nr=nr-1 elif rand_shape==3: ok=1 for x in range(rand_x,rand_x+31,30): for y in range(rand_y,rand_y+31,30): if (x,y)in self.Glist and self.Glist[(x,y)]==True: pass else: ok=0 if ok: for x in range(rand_x,rand_x+31,30): for y in range(rand_y,rand_y+31,30): self.Glist=self.occupy_grid(x,y) ob3=Rectangle(rand_x,rand_y,price,45,self.screen,colours[rand_colour]) self.objects.append(ob3) nr=nr-1 sortedObjList = sorting.bubble(self.objects, user_input[9].lower(), user_input[8].lower()) for item in sortedObjList: print(item) pygame.display.update()
print(value) if value == 9: # To know if their's a mean color or not print('The mean color is ORANGE and RED') else: print('No mean color') # B 2 highest_freq = 30 if highest_freq >= 30: # To determine the mostly worn color of shirt in the week print("The color mostly worn throughout the week is BLUE") else: print("Others") # B 3 value1 = sorting.bubble(q) # To determine the color that is median print(value1) value1a = np.median(value1) print(value1a) if value1a >= 5.5: print("The color that is median is YELLOW AND PINK") else: print("No median color") # B 4 value2 = np.var(q) # To get the variance of colors print(value2) # value2 is the variance of colors # B 5 value3 = stats.probplot(q) # value3 is the color is red