Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. def closest_wins_odds(p1, p2, p3, p4, p5, given_range):
  2.     list_of_inputs = [p1, p2, p3, p4, p5]
  3.     difference_list = []
  4.     player_list = ['Player 1', 'Player 2', 'Player 3', 'Player 4', 'Player 5']
  5.    
  6.     #this should go somewhere to skip unused spots
  7.     for item in list_of_inputs:
  8.         if item == '':
  9.             list_of_inputs.remove(item)
  10.  
  11.     #random choice        
  12.    
  13.     import random
  14.     list_to_pick_from = range(given_range + 1)
  15.     random_choice = random.choice(list_to_pick_from)
  16.    
  17.     #does it have to be indiviual in order to identify which of them won?
  18.    
  19.     for item in list_of_inputs:
  20.         if item == random_choice:
  21.             winning_message = 'Great job %s, you win!' % (player_list[list_of_inputs.index(item)])
  22.  
  23.     # adds the difference between the values to a new, easily accessable list  
  24.    
  25.     for item in list_of_inputs:
  26.         difference_list.append(abs(int(random_choice) - int(item)))
  27.  
  28.     #takes the minimum and assigns its related index in the accessable string player list into the personalized winning_message
  29.  
  30.     for thing in difference_list:
  31.         if thing == min(difference_list):
  32.             winning_message = 'Great job %s, you win!' % (player_list[difference_list.index(thing)])
  33.    
  34.     return winning_message
  35.  
  36. p1 = 1
  37.  
  38. p2 = 2
  39.  
  40. p3 = 3
  41.  
  42. p4 = 4
  43.  
  44. p5 = 5
  45.  
  46. given_range = 6
  47.  
  48. def player_input(p1, p2, p3, p4, p5, given_range):
  49.     input_list = [p1, p2, p3, p4, p5, given_range]
  50.    
  51.     #loops through the items to make sure they meet the criteria in order for it to work and if its nto met asks for a review of the inputs
  52.    
  53.     def is_whole(n):
  54.         if n % 1 == 0:
  55.             return True
  56.  
  57.     for item in input_list:
  58.         if (item > given_range) or (0 > item) or not is_whole(item):
  59.             raise ValueError('Please Retry. Make sure the rules and/or requirements are met.')
  60.  
  61.     print(closest_wins_odds(p1, p2, p3, p4, p5, given_range))
  62.  
  63. player_input(p1, p2, p3, p4, p5, given_range)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement