Skip to content

Commit ce03a46

Browse files
committed
Selecting the throw with numbers.
1 parent 94cafd9 commit ce03a46

File tree

1 file changed

+10
-5
lines changed
  • code/06-organizing-code-with-functions/rocks-game

1 file changed

+10
-5
lines changed

code/06-organizing-code-with-functions/rocks-game/rpsgame.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,18 @@ def check_for_winning_throw(player_1, player_2, roll1, roll2):
8787

8888

8989
def get_roll(player_name, rolls):
90-
roll = input(f"{player_name}, what is your roll? [rock, paper, scissors]: ")
91-
roll = roll.lower().strip()
92-
if roll not in rolls:
93-
print(f"Sorry {player_name}, {roll} is not a valid play!")
90+
print("Available rolls:")
91+
for index, r in enumerate(rolls, start=1):
92+
print(f"{index}. {r}")
93+
94+
text = input(f"{player_name}, what is your roll? ")
95+
selected_index = int(text) - 1
96+
97+
if selected_index < 0 or selected_index >= len(rolls):
98+
print(f"Sorry {player_name}, {text} is out of bounds!")
9499
return None
95100

96-
return roll
101+
return rolls[selected_index]
97102

98103

99104
if __name__ == '__main__':

0 commit comments

Comments
 (0)