Skip to main content
Tweeted twitter.com/StackCodeReview/status/1282374181418663938
Rollback to Revision 3
Source Link
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()

UPDATE

After code review I'm rewrite my code to this. Added multiple starting code and right printing results. Thank for all comments and help. This is great experience for me!

import random

num_wins = 0
num_losses = 0
num_ties = 0

def run_game():
    
    global num_wins, num_losses, num_ties
    
    choices = ["paper", "scissors", "rock"]
    
    user_move = input("Please choice scissors, paper or rock: ")
    while user_move not in choices:
        user_move = input("Please choice scissors, paper or rock: ")
    comp_move = random.choice(choices)

    if user_move == comp_move:
        num_ties += 1
        print(f"BOTH with {user_move} - TIE")
    elif choices[(choices.index(user_move) + 1) % len(choices)] == comp_move:
        num_losses += 1
        print(f"COMPUTER with {comp_move} - WIN!")
    else:
        num_wins += 1
        print(f"USER with {user_move} - WIN!")
        

def print_results():
    print("You win %d times!" % num_wins)
    print("You lose %d times!" % num_losses)
    print("You tie %d times!" % num_ties)

if __name__ == "__main__":
    end = ""
    while end.lower() != "y":
        run_game()
        end = input("Enter 'y'/'Y' to continue ")
    print_results()
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()

UPDATE

After code review I'm rewrite my code to this. Added multiple starting code and right printing results. Thank for all comments and help. This is great experience for me!

import random

num_wins = 0
num_losses = 0
num_ties = 0

def run_game():
    
    global num_wins, num_losses, num_ties
    
    choices = ["paper", "scissors", "rock"]
    
    user_move = input("Please choice scissors, paper or rock: ")
    while user_move not in choices:
        user_move = input("Please choice scissors, paper or rock: ")
    comp_move = random.choice(choices)

    if user_move == comp_move:
        num_ties += 1
        print(f"BOTH with {user_move} - TIE")
    elif choices[(choices.index(user_move) + 1) % len(choices)] == comp_move:
        num_losses += 1
        print(f"COMPUTER with {comp_move} - WIN!")
    else:
        num_wins += 1
        print(f"USER with {user_move} - WIN!")
        

def print_results():
    print("You win %d times!" % num_wins)
    print("You lose %d times!" % num_losses)
    print("You tie %d times!" % num_ties)

if __name__ == "__main__":
    end = ""
    while end.lower() != "y":
        run_game()
        end = input("Enter 'y'/'Y' to continue ")
    print_results()
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()
added 1461 characters in body
Source Link
edrrujqg
  • 53
  • 1
  • 7
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()

UPDATE

After code review I'm rewrite my code to this. Added multiple starting code and right printing results. Thank for all comments and help. This is great experience for me!

import random

num_wins = 0
num_losses = 0
num_ties = 0

def run_game():
    
    global num_wins, num_losses, num_ties
    
    choices = ["paper", "scissors", "rock"]
    
    user_move = input("Please choice scissors, paper or rock: ")
    while user_move not in choices:
        user_move = input("Please choice scissors, paper or rock: ")
    comp_move = random.choice(choices)

    if user_move == comp_move:
        num_ties += 1
        print(f"BOTH with {user_move} - TIE")
    elif choices[(choices.index(user_move) + 1) % len(choices)] == comp_move:
        num_losses += 1
        print(f"COMPUTER with {comp_move} - WIN!")
    else:
        num_wins += 1
        print(f"USER with {user_move} - WIN!")
        

def print_results():
    print("You win %d times!" % num_wins)
    print("You lose %d times!" % num_losses)
    print("You tie %d times!" % num_ties)

if __name__ == "__main__":
    end = ""
    while end.lower() != "y":
        run_game()
        end = input("Enter 'y'/'Y' to continue ")
    print_results()
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()
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()

UPDATE

After code review I'm rewrite my code to this. Added multiple starting code and right printing results. Thank for all comments and help. This is great experience for me!

import random

num_wins = 0
num_losses = 0
num_ties = 0

def run_game():
    
    global num_wins, num_losses, num_ties
    
    choices = ["paper", "scissors", "rock"]
    
    user_move = input("Please choice scissors, paper or rock: ")
    while user_move not in choices:
        user_move = input("Please choice scissors, paper or rock: ")
    comp_move = random.choice(choices)

    if user_move == comp_move:
        num_ties += 1
        print(f"BOTH with {user_move} - TIE")
    elif choices[(choices.index(user_move) + 1) % len(choices)] == comp_move:
        num_losses += 1
        print(f"COMPUTER with {comp_move} - WIN!")
    else:
        num_wins += 1
        print(f"USER with {user_move} - WIN!")
        

def print_results():
    print("You win %d times!" % num_wins)
    print("You lose %d times!" % num_losses)
    print("You tie %d times!" % num_ties)

if __name__ == "__main__":
    end = ""
    while end.lower() != "y":
        run_game()
        end = input("Enter 'y'/'Y' to continue ")
    print_results()
deleted 35 characters in body; edited tags
Source Link
Peilonrayz
  • 43.5k
  • 7
  • 76
  • 155

I'mI am studying and practicing in Python andPython; this is my Rock-Paper-Scissors game I've donebuilt from scratch.
  I'mI saw in the tasksthis task is for beginners. When writing this game. Inin all the examples, I saw dozens of lines of code with if-elif-elseif elif else statements.
  I decided to write the shortest program for this game.

I'm

I'm just looking for any comments, improvements, or bad habits, any. Any comments at all!

Thank you 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()

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()

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()
Became Hot Network Question
hello!
Source Link
edrrujqg
  • 53
  • 1
  • 7
Loading
Source Link
edrrujqg
  • 53
  • 1
  • 7
Loading