def dHighJump(players): print_description('High Jump') stopped_count = 0 # number of players who have faulted scores = [{'going': True, 'height': 0} for player in players] # loops through all heights for height in range(10, 31, 2): print('Current height: {}'.format(height)) # loops through players for id, player in enumerate(players): # player failed if not scores[id]['going']: continue try_it = input('{} - attempt? y/n '.format(player.name)) while not try_it or try_it not in ['y', 'n']: try_it = input('Please enter either y or n') if try_it == 'y': success = input('Did you succeed? y/n ') while not success or try_it not in ['y', 'n']: success = input('Please enter either y or n') if success == 'n': scores[id]['going'] = False stopped_count += 1 else: scores[id]['height'] = height # all players failed if stopped_count == len(players): break # update scores in players dict for id, player in enumerate(players): player.scores['High Jump'] = scores[id]['height'] os.system('clear')
def d110MetreHurdles(players): print_description('110 Metre Hurdles') for player in players: score = input('Score for {}: '.format(player.name)) while not decathlon.validateInput(score, 30, minimum=5): score = input('Please enter a valid number between 5-30: ') score = int(score) player.scores['110 Metre Hurdles'] = score os.system('clear')
def d400Metres(players): print_description('400 Metres') for player in players: score = input('Score for {}: '.format(player.name)) while not decathlon.validateInput(score, 40, minimum=0): score = input('Please enter a valid number from 0 - 40: ') score = int(score) player.scores['400 Metres'] = score os.system('clear')
def heights(players, discipline, min_height, max_height): '''Players roll to reach an increasing value, starting at min_height, and maxing out at max_height''' print_description(discipline) stopped_count = 0 # number of players who have faulted scores = [{'failed': False, 'height': 0} for player in players] # loops through all heights for height in range(min_height, max_height+1, 2): print('Current height: {}'.format(height)) # loops through players for id, player in enumerate(players): # player failed if scores[id]['failed']: continue try_it = input('{} - attempt? y/n: '.format(player.name)) try_it = validateYesOrNo(try_it) if try_it == 'y': success = input('Did you succeed? y/n: ') success = validateYesOrNo(success) if success == 'n': scores[id]['failed'] = True stopped_count += 1 else: scores[id]['height'] = height print() # all players failed if stopped_count == len(players): break # for showing the currently mastered heights os.system('clear') print_scores(players) print_description(discipline) print('Mastered heights:') for id, player in enumerate(players): if scores[id]['failed']: # only shows if player failed still_going = ' - FAILED' else: still_going = '' print('{}: {}{}'.format( player.name, scores[id]['height'], still_going)) print('\n') # update scores in players dict for id, player in enumerate(players): player.scores[discipline] = scores[id]['height'] os.system('clear') updateTotals(players)
def dLongJump(players): print_description('Long Jump') for player in players: print('\n{} attempts'.format(player.name)) best_score = 0 for attempt in range(1, 4): score = input('Attempt {}: '.format(attempt)) while not decathlon.validateInput(score, 30): score = input('Please enter a number from 0-30: ') score = int(score) best_score = max(best_score, score) player.scores['Long Jump'] = best_score print() os.system('clear')
def one_attempt(players, discipline, min_score, max_score): '''Players get one attempt at the discipline. Possible scores are min_score <= score <= max_score''' print_description(discipline) for player in players: score = input('Score for {}: '.format(player.name)) score = decathlon.validateInput(score, minimum=min_score, maximum=max_score) player.scores[discipline] = score os.system('clear') updateTotals(players)
def dShotPut(players): print_description('Shot Put') for player in players: print('\n{} attempts'.format(player.name)) best_score = 0 for attempt in range(1, 4): score = input('Attempt {}: '.format(attempt)) while not decathlon.validateInput( score, 40, minimum=8, invalid=True): score = input('Please enter a valid number from 0-40: ') score = int(score) best_score = max(best_score, score) player.scores['Shot Put'] = best_score print() os.system('clear')
def dDiscus(players): print_description('Discus') for player in players: print('\n{} attempts'.format(player.name)) best_score = 0 for attempt in range(1, 4): score = input('Attempt {}: '.format(attempt)) while not decathlon.validateInput( score, 30, minimum=10, invalid=True): score = input('Please enter a valid number between 10-30: ') score = int(score) best_score = max(best_score, score) player.scores['Discus'] = best_score print() os.system('clear')
def three_attempts(players, discipline, min_score, max_score): '''Players have three attempts to get the highest score possible. Scores range from min_score <= score <= max_score''' print_description(discipline) for player in players: print('\n{} attempts'.format(player.name)) best_score = 0 for attempt in range(1, 4): score = input('Attempt {}: '.format(attempt)) score = decathlon.validateInput(score, minimum=min_score, maximum=max_score, invalid=True) best_score = max(best_score, score) player.scores[discipline] = best_score print() os.system('clear') updateTotals(players)