I'm studying and practicing in Python and this is my Rock-Paper-Scissors game I've done from scratch.
I'm saw in the tasks for beginners writing this game. 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, bad habits, any comments at all!
Thank you!
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()