Advertisement
fly51fly

choujiang

Nov 8th, 2021
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. import random
  2. import time
  3.  
  4. def chou_1(u_list):
  5.     selected_user_info = random.choice(u_list).split('\t')
  6.     print(f"恭喜中奖用户:{selected_user_info[0]} {selected_user_info[1]}")
  7.     return selected_user_info[0]
  8.  
  9. def chou_2(u_list):
  10.     while 1:
  11.         try:
  12.             idx = int(time.time() * 1000) % len(u_list)
  13.             print(f"\r{u_list[idx]}    ", end='')
  14.             time.sleep(0.001)
  15.         except KeyboardInterrupt:
  16.             break
  17.     selected_user_info = u_list[idx].split('\t')
  18.     print(f"\r恭喜中奖用户:{selected_user_info[0]} {selected_user_info[1]}              ")
  19.     return selected_user_info[0]
  20.  
  21. def chou_3(u_list):
  22.     while 1:
  23.         rand_x = random.randint(0, 10000) / 10
  24.         rand_y = random.randint(0, 10000) / 10
  25.         try:
  26.             print(f"\r{rand_x},{rand_y}", end='')
  27.             time.sleep(0.1)
  28.         except KeyboardInterrupt:
  29.             break
  30.  
  31.     user_distance_list = []
  32.     for user_info in u_list:
  33.         uid, uname, ux, uy = user_info.split('\t')
  34.         distance = int((int(ux) - rand_x) ** 2 + (int(uy) - rand_y) ** 2)
  35.         user_distance_list.append((uid, uname, distance))
  36.    
  37.     user_distance_list.sort(key=lambda x:x[2])
  38.     print(f"\r恭喜中奖用户:{user_distance_list[0][0]} {user_distance_list[0][1]}")
  39.  
  40. def main():
  41.     with open('users.txt') as f:
  42.         content = f.read()
  43.  
  44.     user_list = content.split("\n")
  45.    
  46.     chou_1(user_list)
  47.     chou_2(user_list)
  48.     chou_3(user_list)
  49.  
  50. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement