Best Python code snippet using autotest_python
8-puzzle_0.py
Source:8-puzzle_0.py
...221 var_heuristic = heuristic()222 numbers_photos_list[position_snake], numbers_photos_list[position_future] = numbers_photos_list[position_future], numbers_photos_list[position_snake]223 return var_heuristic224 225 def change_position(nesxt_snake_position):226 position_snake = numbers_photos_list.index(snake_photo)227 position_snake_future = numbers_photos_list.index(nesxt_snake_position)228 numbers_photos_list[position_snake], numbers_photos_list[position_snake_future] = numbers_photos_list[position_snake_future], numbers_photos_list[position_snake]229 def find_min_heuristic(heuristic_val_list):#I takes a list of heuristic valeus and returns a list with the position numbers(at the heuristic values list) of the min heuristics 230 new_list = []231 val_list = heuristic_val_list232 min_val = min(val_list)233 for i in range(len(heuristic_val_list)):234 if heuristic_val_list[i] == min_val:235 new_list += [i]236 return new_list237 238 def auto():239 if snake_photo == position_0:240 val_1 = next_step_heuristic(position_1)241 val_2 = next_step_heuristic(position_3)242 if snake_queue[0]==1: #if snake in the previous move at this position i make the heuristic large to avoid a step back 243 val_1 = 50244 if snake_queue[0]==3:245 val_2 = 50246 print(f'Fidi deksia:{val_1}, Fidi kato:{val_2}') 247 if val_1 >= val_2:248 change_position(position_3)249 refresh_game()250 else:251 change_position(position_1)252 refresh_game()253 elif snake_photo == position_1:254 val_1 = next_step_heuristic(position_0)255 val_2 = next_step_heuristic(position_2)256 val_3 = next_step_heuristic(position_4)257 if snake_queue[0]==0:258 val_1 = 50259 if snake_queue[0]==2:260 val_2 = 50261 if snake_queue[0]==4:262 val_3 = 50263 min_heuristic_positions = find_min_heuristic([val_1,val_2,val_3])264 print(f'Fidi aristera:{val_1}, Fidi deksia:{val_2}, Fidi kato:{val_3}')265 if len(min_heuristic_positions)==1: 266 if val_1 >= val_3 and val_2>=val_3:267 change_position(position_4)268 refresh_game()269 elif val_1 >=val_2 and val_3>=val_2:270 change_position(position_2)271 refresh_game()272 else:273 change_position(position_0)274 refresh_game()275 else:276 position_number = int(random.choice(min_heuristic_positions)) # if two or more heuristics are equal i randomize the choice of the path to avoid infinite loop 277 if position_number == 0:278 change_position(position_0)279 refresh_game()280 elif position_number == 1:281 change_position(position_2)282 refresh_game()283 else:284 change_position(position_4)285 refresh_game()286 elif snake_photo == position_2:287 val_1 = next_step_heuristic(position_1)288 val_2 = next_step_heuristic(position_5)289 if snake_queue[0]==1:290 val_1 = 50291 if snake_queue[0]==5:292 val_2 = 50293 print(f'Fidi aristera:{val_1}, Fidi kato:{val_2}') 294 if val_1 >= val_2:295 change_position(position_5)296 refresh_game()297 else:298 change_position(position_1)299 refresh_game()300 elif snake_photo == position_3:301 val_1 = next_step_heuristic(position_0)302 val_2 = next_step_heuristic(position_4)303 val_3 = next_step_heuristic(position_6)304 if snake_queue[0]==0:305 val_1 = 50306 if snake_queue[0]==4:307 val_2 = 50308 if snake_queue[0]==6:309 val_3 = 50 310 min_heuristic_positions = find_min_heuristic([val_1,val_2,val_3])311 print(f'Fidi pano:{val_1}, Fidi deksia:{val_2}, Fidi kato:{val_3}')312 if len(min_heuristic_positions)==1:313 if val_1 >= val_3 and val_2>=val_3:314 change_position(position_6)315 refresh_game()316 elif val_1 >=val_2 and val_3>=val_2:317 change_position(position_4)318 refresh_game()319 else:320 change_position(position_0)321 refresh_game()322 else:323 position_number = int(random.choice(min_heuristic_positions))324 if position_number == 0:325 change_position(position_0)326 refresh_game()327 elif position_number == 1:328 change_position(position_4)329 refresh_game()330 else:331 change_position(position_6)332 refresh_game()333 elif snake_photo == position_4:334 val_1 = next_step_heuristic(position_1)335 val_2 = next_step_heuristic(position_3)336 val_3 = next_step_heuristic(position_5)337 val_4 = next_step_heuristic(position_7)338 if snake_queue[0]==1:339 val_1 = 50340 if snake_queue[0]==3:341 val_2 = 50342 if snake_queue[0]==5:343 val_3 = 50344 if snake_queue[0]==7:345 val_4 = 50 346 min_heuristic_positions = find_min_heuristic([val_1,val_2,val_3,val_4])347 print(f'Fidi pano:{val_1}, Fidi aristera:{val_2}, Fidi deksia:{val_3}, Fidi kato:{val_4}')348 if len(min_heuristic_positions)==1: 349 if val_1 >= val_4 and val_2>=val_4 and val_3 >= val_4:350 change_position(position_7)351 refresh_game()352 elif val_1 >= val_3 and val_2>=val_3 and val_4 >= val_3:353 change_position(position_5)354 refresh_game()355 elif val_1 >= val_2 and val_3>=val_2 and val_4 >= val_2:356 change_position(position_3)357 refresh_game()358 else:359 change_position(position_1)360 refresh_game()361 else:362 position_number = int(random.choice(min_heuristic_positions))363 if position_number == 0:364 change_position(position_1)365 refresh_game()366 elif position_number == 1:367 change_position(position_3)368 refresh_game()369 elif position_number == 2:370 change_position(position_5)371 refresh_game()372 else:373 change_position(position_7)374 refresh_game()375 elif snake_photo == position_5:376 val_1 = next_step_heuristic(position_2)377 val_2 = next_step_heuristic(position_4)378 val_3 = next_step_heuristic(position_8)379 if snake_queue[0]==2:380 val_1 = 50381 if snake_queue[0]==4:382 val_2 = 50383 if snake_queue[0]==8:384 val_3 = 50385 min_heuristic_positions = find_min_heuristic([val_1,val_2,val_3])386 print(f'Fidi pano:{val_1}, Fidi aristera:{val_2}, Fidi kato:{val_3}')387 if len(min_heuristic_positions)==1: 388 if val_1 >= val_3 and val_2>=val_3:389 change_position(position_8)390 refresh_game()391 elif val_1 >=val_2 and val_3>=val_2:392 change_position(position_4)393 refresh_game()394 else:395 change_position(position_2)396 refresh_game()397 else:398 position_number = int(random.choice(min_heuristic_positions))399 if position_number == 0:400 change_position(position_2)401 refresh_game()402 elif position_number == 1:403 change_position(position_4)404 refresh_game()405 else:406 change_position(position_8)407 refresh_game()408 elif snake_photo == position_6:409 val_1 = next_step_heuristic(position_3)410 val_2 = next_step_heuristic(position_7)411 if snake_queue[0]==3:412 val_1 = 50413 if snake_queue[0]==7:414 val_2 = 50415 print(f'Fidi pano:{val_1}, Fidi deksia:{val_2}') 416 if val_1 >= val_2:417 change_position(position_7)418 refresh_game()419 else:420 change_position(position_3)421 refresh_game()422 423 elif snake_photo == position_7:424 val_1 = next_step_heuristic(position_4)425 val_2 = next_step_heuristic(position_6)426 val_3 = next_step_heuristic(position_8)427 if snake_queue[0]==4:428 val_1 = 50429 if snake_queue[0]==6:430 val_2 = 50431 if snake_queue[0]==8:432 val_3 = 50433 min_heuristic_positions = find_min_heuristic([val_1,val_2,val_3])434 print(f'Fidi pano:{val_1}, Fidi aristera:{val_2}, Fidi deksia:{val_3}')435 if len(min_heuristic_positions)==1: 436 if val_1 >= val_3 and val_2>=val_3:437 change_position(position_8)438 refresh_game()439 elif val_1 >=val_2 and val_3>=val_2:440 change_position(position_6)441 refresh_game()442 else:443 change_position(position_4)444 refresh_game()445 else:446 position_number = int(random.choice(min_heuristic_positions))447 if position_number == 0:448 change_position(position_4)449 refresh_game()450 elif position_number == 1:451 change_position(position_6)452 refresh_game()453 else:454 change_position(position_8)455 refresh_game()456 457 elif snake_photo == position_8:458 val_1 = next_step_heuristic(position_7)459 val_2 = next_step_heuristic(position_5)460 if snake_queue[0]==7:461 val_1 = 50462 if snake_queue[0]==5:463 val_2 = 50464 print(f'Fidi aristera:{val_1}, Fidi pano:{val_2}') 465 if val_1 >= val_2:466 change_position(position_5)467 refresh_game()468 else:469 change_position(position_7)470 refresh_game()471 472 def left_button_fun():473 if snake_photo == position_1:474 change_position(position_0)475 refresh_game()476 elif snake_photo == position_2:477 change_position(position_1)478 refresh_game()479 elif snake_photo == position_4:480 change_position(position_3)481 refresh_game()482 elif snake_photo == position_5:483 change_position(position_4)484 refresh_game()485 elif snake_photo == position_7:486 change_position(position_6)487 refresh_game()488 elif snake_photo == position_8:489 change_position(position_7)490 refresh_game()491 def right_button_fun():492 if snake_photo == position_1:493 change_position(position_2)494 refresh_game()495 elif snake_photo == position_0:496 change_position(position_1)497 refresh_game()498 elif snake_photo == position_4:499 change_position(position_5)500 refresh_game()501 elif snake_photo == position_3:502 change_position(position_4) 503 refresh_game()504 elif snake_photo == position_7:505 change_position(position_8)506 refresh_game()507 elif snake_photo == position_6:508 change_position(position_7)509 refresh_game()510 def up_button_fun():511 if snake_photo == position_5:512 change_position(position_2)513 refresh_game()514 elif snake_photo == position_4:515 change_position(position_1)516 refresh_game()517 elif snake_photo == position_8:518 change_position(position_5)519 refresh_game()520 elif snake_photo == position_7:521 change_position(position_4)522 refresh_game()523 elif snake_photo == position_3:524 change_position(position_0)525 refresh_game()526 elif snake_photo == position_6:527 change_position(position_3)528 refresh_game()529 def down_button_fun():530 if snake_photo == position_3:531 change_position(position_6)532 refresh_game()533 elif snake_photo == position_0:534 change_position(position_3)535 refresh_game()536 elif snake_photo == position_2:537 change_position(position_5)538 refresh_game()539 elif snake_photo == position_1:540 change_position(position_4)541 refresh_game()542 elif snake_photo == position_5:543 change_position(position_8)544 refresh_game()545 elif snake_photo == position_4:546 change_position(position_7)547 refresh_game()548 left_button = Button(frame_12, image=left_photo, command=left_button_fun)549 left_button.grid(row=0, column=0)550 right_button = Button(frame_12, image=right_photo, command=right_button_fun)551 right_button.grid(row=0, column=1)552 up_button = Button(frame_14, image=up_photo, command=up_button_fun)553 up_button.grid(row=0, column=0)554 down_button = Button(frame_14, image=down_photo, command=down_button_fun)555 down_button.grid(row=0, column=1)556 shuf_button = Button(frame_9, image=shuf_photo, command=shuf_photos)557 shuf_button.pack()558 exit_button = Button(frame_11, image=exit_photo, command=root.destroy)559 exit_button.pack()560 if numbers_photos_list == [number_1_photo, number_2_photo, number_3_photo, number_8_photo, snake_photo, number_4_photo, number_7_photo, number_6_photo, number_5_photo]:...
1244.py
Source:1244.py
1import sys2sys.stdin = open('input.txt', 'r')3switch_count = int(input())4switch_list = list(map(int, input().split()))5student_count = int(input())6for _ in range(student_count):7 gender, g_count = map(int, input().split())8 # ë¨íì꺼 ì²ë¦¬9 if gender == 1:10 for a in range(switch_count//g_count):11 change_position = g_count * (a + 1) - 112 switch_list[change_position] = (switch_list[change_position] + 1) % 213 # ì¬íì꺼 ì²ë¦¬14 else:15 # ì¼ë¨ ê·¸ ì리 ì°ì ë°ê¾¸ê³ ììíì16 change_position = g_count - 117 switch_list[change_position] = (switch_list[change_position] + 1) % 218 range_num = min(change_position, switch_count - change_position - 1)19 for b in range(range_num):20 if switch_list[change_position - (b + 1)] != switch_list[change_position + (b + 1)]:21 break22 else:23 switch_list[change_position - (b + 1)] = (switch_list[change_position - (b + 1)] + 1) % 224 switch_list[change_position + (b + 1)] = (switch_list[change_position + (b + 1)] + 1) % 225 if not change_position - b or change_position + b == switch_count - 1:26 break27# ì¶ë ¥ ê·ì¹ì ë§ê² ì¶ë ¥28for i in range(switch_count):29 if not i % 20:30 if i:31 print(result)32 result = ''33 if i % 20 == 19:34 result += str(switch_list[i])35 else:36 result += str(switch_list[i]) + ' '37if result:...
draw.py
Source:draw.py
...3# turtle.setundobuffer(15)4turtle.pensize(3)5turtle.speed(1000)6s = turtle.Screen()7def change_position(x,y):8 turtle.penup()9 turtle.setposition(x,y)10 turtle.pendown()11 # print(x,y)12def box_draw(pos_x: int, pos_y: int, size: int):13 '''Making a box a 'size' value away in all directions starting from (pos_x, pos_y)'''14 change_position(pos_x + size,pos_y)15 turtle.goto(pos_x + size,pos_y + size) # 116 marker_1 = turtle.position()17 turtle.goto(pos_x - size,pos_y + size) # 218 marker_2 = turtle.position()19 turtle.goto(pos_x - size,pos_y - size) # 320 marker_3 = turtle.position()21 turtle.goto(pos_x + size,pos_y - size) # 422 marker_4 = turtle.position()23 turtle.goto(pos_x + size,pos_y)24 change_position(pos_x,pos_y)25 box_markers = (marker_1, marker_2, marker_3, marker_4)26 return box_markers27def is_free(pos_x, pos_y):28 pass29def board(how_many:int, size_x:int, size_y:int):30 '''Making a (2*size_x : 2*size_y) board with 'how_many' items on it'''31 for i in range(1,how_many + 1):32 x = randint(-size_x + 30,size_x - 30) # +- 30 for making all of the boxes fully visible on the screen33 y = randint(-size_y + 30,size_y - 30)34 is_free(x,y) # ultimately is to select coordinates35 box_draw(x,y,25)36 change_position(x, y - 25)37 turtle.write(str(i),True, align='center',font=('Arial',30,'normal'))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!