I am studying and practicing Python; this is my Rock-Paper-Scissors game I've built from scratch.
I saw this task is for beginners. When writing this in all the examples I saw dozens of lines of code with if
elif
else
statements.
I decided to write the shortest program for this game.
I'm just looking for any comments, improvements or bad habits. Any comments at all are welcome!
import random
my_win = 0
my_loss = 0
my_tie = 0
def game():
global my_tie, my_loss, my_win
var = {'scissors':(0,1,0),
'paper':(0,0,1),
'rock':(1,0,0)}
user = input("Please choice scissors, paper or rock: ")
while user not in ['scissors', 'paper', 'rock']:
user = input("Please choice scissors, paper or rock: ")
computer = random.choice(['scissors','paper','rock'])
print(f"USER - {user} \nCOMPUTER - {computer}")
for k, v in var.items():
if k == user:
one = int(v.index(1))
if k == computer:
two = int(v.index(1))
if one < two:
print(f"USER with {user} - WIN!")
my_win += 1
elif one == two:
print("==TIE==")
my_tie += 1
else:
print(f"COMPUTER with {computer} - WIN!")
my_loss += 1
def results():
print ("You win %d times!" % my_win)
print ("You lose %d times!" % my_loss)
print ("You tie %d times!" % my_tie)
if __name__ == "__main__":
game()