Created
October 1, 2018 13:15
-
-
Save thorpj/5215a5fff4fce2bfab4852e810f39584 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
horse_names = [] | |
horse_finish_times = [] | |
def register_horse(horse_name, horse_number): | |
horse = [horse_number, horse_name] | |
horse_names.append(horse) | |
print("Registered horse") | |
def record_race_data(horse_number, finish_time): | |
horse = [horse_number, finish_time] | |
horse_finish_times.append(horse) | |
print("Recorded horse finish time") | |
def calculate_race_winner(): | |
lowest_time = 10000 | |
horse_number = 0 | |
for i in range(0, len(horse_names)): | |
finish_time = horse_finish_times[i][1] | |
if finish_time < lowest_time: | |
lowest_time = finish_time | |
horse_number = horse_finish_times[i][0] | |
fastest_horse_number = horse_number | |
print("Fastest horse is {}".format(fastest_horse_number)) | |
return fastest_horse_number | |
def display_times(): | |
for i in range(0, len(horse_names)): | |
print("Number: {} Name: {} Finish Time: {}".format(horse_names[i][0], horse_names[i][1], horse_finish_times[i][1])) | |
def print_horse_name(horse_number): | |
# print horse name given a horse number | |
for i in range(0, len(horse_names)): | |
current_horse_number = horse_names[i][0] | |
if current_horse_number == horse_number: | |
print("Horse with number {} is {}".format(horse_number, horse_names[i][1])) | |
def get_horse_number(): | |
horse_number = "" | |
while horse_number == "": | |
try: | |
horse_number = input("Horse Number: ") | |
horse_number = int(horse_number) | |
except ValueError: | |
print("Please enter the horse number correctly.") | |
horse_number = "" | |
return horse_number | |
def get_horse_finish_time(): | |
horse_number = "" | |
while horse_number == "": | |
try: | |
horse_number = input("Horse Finish Time: ") | |
horse_number = int(horse_number) | |
except ValueError: | |
print("Please enter the horse finish time correctly.") | |
horse_number = "" | |
return horse_number | |
def main(): | |
horse_count = 3 | |
for i in range(0, horse_count): | |
horse_number = get_horse_number() | |
horse_name = input("Horse Name: ") | |
register_horse(horse_name, horse_number) | |
for i in range(0, horse_count): | |
horse_number = get_horse_number() | |
horse_finish_time = get_horse_finish_time() | |
record_race_data(horse_number, horse_finish_time) | |
fastest_horse_number = calculate_race_winner() | |
print_horse_name(fastest_horse_number) | |
display_times() | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment