xxxxxxxxxx
1from random import randint
2
3
4#creating the arrays
5horses = ["Louie","Blackjack","Harry","Eric","Honey","Cassie","Ted","Reuben"]
6horse_in_stable = [False, False, False, False, False, False, False, False]
7stables = [0, 1, 2, 3, 4]
8guess_stables = [0, 1, 2, 3, 4]
9
10
11
12
13#assigning a horse to a random stable
14for empty_stable in range(0,5,1):
15value=randint(0, 7)
16while horse_in_stable [value]:
17value = randint (0,7)
18stables[empty_stable] = value
19horse_in_stable[value] = True
20
21for horse_counter in range(0,8,1):
22print(str(horse_counter) + " " + horses[horse_counter])
23
24print (" ")
25print ("Input your horses in stable order")
26#creating the input for the guesses
27all_guesses_correct = False
28goes = 0
29while not all_guesses_correct:
30goes = goes + 1
31guess_order = input()
32guess_stables[0] = int(guess_order[0:1])
33guess_stables[1] = int(guess_order[1:2])
34guess_stables[2] = int(guess_order[2:3])
35guess_stables[3] = int(guess_order[3:4])
36guess_stables[4] = int(guess_order[4:5])
37
38
39# print (" ")
40# print (print_string)
41# print (" ")
42# print (" Stable 0 Stable 1 Stable 2 Stable 3 Stable 4")
43#matching the guesses with the randomly generated stables
44print_string = " "
45for compare_counter in range(0,5,1):
46if stables[compare_counter] == guess_stables[compare_counter]:
47print_string = print_string+" [" + str(guess_stables[compare_counter]) + " " + horses[guess_stables[compare_counter]] + " ] "
48elif guess_stables[compare_counter] in stables:
49print_string = print_string +" [ " + str(guess_stables[compare_counter]) + " Wrong Stable " + " ] "
50else:
51print_string = print_string + " [ ] "
52
53print(print_string)
54#questioning if the guesses match all the stables generated
55if guess_stables == stables:
56print("You got them all correct in " + str (goes) + " goes")
57all_guesses_correct = True
Variables:
Renaming a project helps you organise your saved code
Be careful: if you choose to delete a file, you will not be able to recover it unless you've saved a copy
create.withcode.uk allows you to write, run, debug and share python code in your web browser.
Anyone can access your code using this link:
Copy and paste this html to embed your code in a blog / website:
You will need this plugin installed on your site first.