Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def closest_wins_odds(p1, p2, p3, p4, p5, given_range):
- list_of_inputs = [p1, p2, p3, p4, p5]
- difference_list = []
- player_list = ['Player 1', 'Player 2', 'Player 3', 'Player 4', 'Player 5']
- #this should go somewhere to skip unused spots
- for item in list_of_inputs:
- if item == '':
- list_of_inputs.remove(item)
- #random choice
- import random
- list_to_pick_from = range(given_range + 1)
- random_choice = random.choice(list_to_pick_from)
- #does it have to be indiviual in order to identify which of them won?
- for item in list_of_inputs:
- if item == random_choice:
- winning_message = 'Great job %s, you win!' % (player_list[list_of_inputs.index(item)])
- # adds the difference between the values to a new, easily accessable list
- for item in list_of_inputs:
- difference_list.append(abs(int(random_choice) - int(item)))
- #takes the minimum and assigns its related index in the accessable string player list into the personalized winning_message
- for thing in difference_list:
- if thing == min(difference_list):
- winning_message = 'Great job %s, you win!' % (player_list[difference_list.index(thing)])
- return winning_message
- p1 = 1
- p2 = 2
- p3 = 3
- p4 = 4
- p5 = 5
- given_range = 6
- def player_input(p1, p2, p3, p4, p5, given_range):
- input_list = [p1, p2, p3, p4, p5, given_range]
- #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
- def is_whole(n):
- if n % 1 == 0:
- return True
- for item in input_list:
- if (item > given_range) or (0 > item) or not is_whole(item):
- raise ValueError('Please Retry. Make sure the rules and/or requirements are met.')
- print(closest_wins_odds(p1, p2, p3, p4, p5, given_range))
- player_input(p1, p2, p3, p4, p5, given_range)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement