>
>
> I coded Rock, Paper, Scissors. I added the randomness, made it loop at the
> user's request, added win code, no problems there. I changed some strings
> to F-strings to practice using them, and now the first "elif" in my if loop
> (player chooses rock, bot chooses paper) doesn't work. Any help ideas? I
> checked syntax, no error messages other than mine that I added
> Pasting code below the line:
>
> _____________________________________________________________________________
> import random #Allows for a random input.
> options = ["Rock", "Paper", "Scissors"] #Tells the computer what its
> options are.
> playerchoices = []
> repeat = True
> while repeat == True:
> rand_choice = random.randint(1,3)
> choice = options[rand_choice-1] #defines player options and selection
> while True:
> player_choice = input("Welcome to Rock, Paper, Scissors. To begin,
> choose Rock, Paper, or Scissors. ")
> if player_choice == "Rock":
> break
> if player_choice == "Paper":
> break
> if player_choice == "Scissors":
> ...
>
One practice I follow is declaring strings, _especially_ those used more
than once, at the top:
import random #Allows for a random input.
ROCK = "Rock" # Defined once
PAPER = "Paper" # Defined once
SCISSORS = "Scissors" # Defined once
options = [ROCK, PAPER, SCISSORS] #Tells the computer what its options are.
playerchoices = []
repeat = True
while repeat == True:
rand_choice = random.randint(1,3)
choice = options[rand_choice-1] #defines player options and selection
while True:
player_choice = input("Welcome to Rock, Paper, Scissors. To begin,
choose Rock, Paper, or Scissors. ")
if player_choice == ROCK:
break
if player_choice == PAPER:
break
if player_choice == SCISSORS:
...
The advantage of this approach is misspellings generate compilation errors,
which are easier to catch and fix.
--
https://mail.python.org/mailman3//lists/python-list.python.org