Python Programming - Creating a Rock, Paper, Scissors Game

preview_player
Показать описание
Welcome to another video of the Python Programming tutorial series here on Tutorial Spot.

In this quick video I will show you how to create a simple Rock, Paper, Scissors game. This game requires random module, user input, and selection through the use of if/elif statements.

I hope you enjoyed or found it useful.

Code uploaded to PasteBin:

Visual Studio Code / Python 3.7.2 was used to make this tutorial.

Twitter: @TutorialSpotUK
Рекомендации по теме
Комментарии
Автор

You made it easy to understand, thank you!

mariamahady
Автор

actions = ['rock', 'paper', 'scissors']
for i in range(1, 4):
if action == actions[i-1] or action == actions[i-1]: action = i
botact = random.randint(1, 3)
if action in range(1, 4):
if action == botact: print(f"> player chose {actions[action-1]}.\nThe computer chose {actions[botact-1]}.\nIt's a tie!")
if action + 1 == botact or action + 2 == botact: print(f'> player chose {actions[action-1]}.\n> The computer chose {actions[botact-1]}.\n> The computer won.')
if action == botact + 1 or action == botact + 2: print(f'> player chose {actions[action-1]}.\n> The computer chose {actions[botact-1]}.\n> player won!')
else: print(f'Invalid input.')
here's a much more effective way than writing if statements for the 7 possible outcomes of rock paper scissors

u
Автор

Thank you so much! I did so much research and this was found to be the most clean cut. Im so confused on the for/while loops and try/except functions D:

kararahn
Автор

import random
game = ["ROCK", "PAPER", "SCISSORS"]
play1, play2 = random.randint(0, 2), random.randint(0, 2)
if play1 == play2:
print("DRAW [ Player 1:", game[play1], "= Player 2:", game[play2], "]")
elif play1 - play2 == 1 or play2 - play1 == 2:
print("WIN Player 1:", game[play1], "Player 2:", game[play2])
elif play2 - play1 == 1 or play1 - play2 == 2:
print("WIN Player 2:", game[play2], "Player 1:", game[play1])

JavierDt
Автор

thank you but can you do a close up next time? I can barely read what youre coding, thank you!

serlolol
Автор

can I make it where it doesn't loop?

sooryaraju