Skip to content

Commit 2be2190

Browse files
committed
Fix style for Snookle Game
1 parent 780808d commit 2be2190

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
"""
22
Snookle Game
3-
Snookle the sheep wants to play a game.
4-
Given a list of positive integers and a main number, the player iterates
5-
through each element in the list and chooses to either add it or
6-
to subtract it from the current main number.
3+
Snookle the sheep wants to play a game.
4+
Given a list of positive integers and a main number, the player iterates
5+
through each element in the list and chooses to either add it or
6+
to subtract it from the current main number.
7+
78
This is done by having the user enter either 'add' or 'subtract' every turn.
89
The main number will be updated to the new value.
10+
911
A player wins if they make 12 to be the main number.
10-
If the end of the list is reached, go back to the first element
12+
If the end of the list is reached, go back to the first element
1113
in the list and keep going until the player wins.
12-
Code the game for Snookle!
14+
Code the game for Snookle!
1315
"""
1416

15-
#example values to get you started
16-
nums = [3,1,4,2,6,5,8,10]
17+
# example values to get you started
18+
nums = [3, 1, 4, 2, 6, 5, 8, 10]
1719
main = 7
Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
11
"""
22
Snookle Game
3-
Snookle the sheep wants to play a game.
4-
Given a list of positive integers and a main number, the player iterates
5-
through each element in the list and chooses to either add it or
6-
to subtract it from the current main number.
3+
Snookle the sheep wants to play a game.
4+
Given a list of positive integers and a main number, the player iterates
5+
through each element in the list and chooses to either add it or
6+
to subtract it from the current main number.
7+
78
This is done by having the user enter either 'add' or 'subtract' every turn.
89
The main number will be updated to the new value.
10+
911
A player wins if they make 12 to be the main number.
10-
If the end of the list is reached, go back to the first element
12+
If the end of the list is reached, go back to the first element
1113
in the list and keep going until the player wins.
12-
Code the game for Snookle!
14+
Code the game for Snookle!
1315
"""
1416

15-
nums = [3,1,4,2,6,5,8,10]
17+
# example values to get you started
18+
nums = [3, 1, 4, 2, 6, 5, 8, 10]
1619
main = 7
1720

18-
choice = ''
19-
win = False #The game keeps going until this variable is set to True
20-
21-
while (not win):
22-
for i in nums:
23-
print('main number is currently ' + str(main)) #this is optional, but it's easier for the players since they won't have to keep track of the math
24-
choice = input("[add] or [subtract] " + str(i) + "?\n> ") #text is also optional, I just added it to make it more user-friendly
25-
if(choice == 'add'): #The user chooses to add
26-
main += i #update main value
27-
elif(choice == 'subtract'): #The user chooses to subtract
28-
main -= i #update main value
29-
if(main == 12): #If the main number if 12, the user has won!
30-
win = True #This will make the program exit out of the while loop, thus ending the game
31-
break #This takes us out of the for loop and straight to the while statement
21+
win = False # The game keeps going until this variable is set to True
22+
23+
while not win:
24+
for num in nums:
25+
# prompt user to add or subtract current num
26+
print('main number is currently ' + str(main))
27+
choice = input("[add] or [subtract] " + str(num) + "?\n> ")
28+
29+
# update main value based on choice
30+
if choice == 'add':
31+
main += num
32+
elif choice == 'subtract':
33+
main -= num
34+
35+
# If the main number if 12, the user has won!
36+
if main == 12:
37+
win = True # Exit while loop and end game
38+
break # Exit for loop
3239

3340
print('Congrats you won the game!')

0 commit comments

Comments
 (0)