Skip to content

Commit bf11cfc

Browse files
committed
Fixed errorhandling for wrong input
1 parent dd5939d commit bf11cfc

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

stone_paper_scissor/main.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
player_name = input('Please enter your name: ') # Takes Input from the user
77

88
print('Pick a hand: (0: Rock, 1: Paper, 2: Scissors)')
9-
player_hand = int(input('Please enter a number (0-2): '))
9+
10+
while True:
11+
try:
12+
player_hand = int(input('Please enter a number (0-2): '))
13+
if player_hand not in range(0, 3):
14+
raise ValueError
15+
else:
16+
break
17+
except ValueError as e:
18+
print('Please input a correct number')
1019

1120
if utils.validate(player_hand):
1221
# Assign a random number between 0 and 2 to computer_hand using randint

0 commit comments

Comments
 (0)