How do i make a rock, paper, scissor game using python.
I'm so Confused.
You can do this with the random module, a few if statements, and an input prompt. For example:
import random options = ["Rock", "Paper", "Scissors"] print("Welcome to a Python Rock Paper Scissors Program!" # The function below merely decides who wins. It's a lot cleaner than using a loop. def victory(player, bot): # The .capitalize() operation on the player variable makes the function neater since it automatically capitalizes it for us. This makes it so we don't have to use an "or" logic gate to check for non-capitalized inputs as well. Aside from that, the order of the logic gates do not matter. if player.capitalize() == bot: return "D'oh, we tied! Wanna rematch?" elif player.capitalize() == "Rock" and bot == "Scissors": return "Scissors! You beat me..." elif player.capitalize() == "Paper" and bot == "Rock": return "Rock! You beat me..." elif player.capitalize() == "Scissors" and bot == "Paper": return "Paper! You beat me..." elif player.capitalize() == "Scissors" and bot == "Rock": return "Rock! I win!" elif player.capitalize() == "Paper" and bot == "Scissors": return "Scissors! I win!" elif player.capitalize() == "Rock" and bot == "Paper": return "Paper! I win!" else: return "Sorry, that wasn't an option. Try again please." player_choice = input("Ready? Rock, Paper, Scissors, Shoot! " # This is utilizing the random module to randomly select one of the options for the computer. print(victory(player_choice, random.choice(options)))
I believe that's about as down-to-earth simple as it gets. Let me know if you have any questions.
@Programmer90 I think I made a mistake. Try replacing random.choice(options) with random.randint(1, 3), the replace all of the string arguments for the logic gates on the bot side with numbers (for example, instead of bot == "Rock", it would be bot == 1, for bot == "Scissors" it would be bot == 2. Don't worry about changing the player_choice side though, as we're still putting in the same data type.)
All this change does is change the data type to work since it seems the first method didn't work. If it still gives you issues, try adding a second argument to the return statement. You can do this by adding a comma at the end and typing in your second data argument. (For example, return "Rock! You win!", "Some data here" . Please note that this doesn't have to be a string. It can be any form of data, like integers, lists, booleans, etc. If you don't want the second value to appear in the console, just make it an empty string (or "").
I hope this helped!