Dec-25-2017, 03:41 PM
"""A basic program/game that simulates Rock-Paper-Scissors with text""" # I need random library to randomise the bot's actions. import random # Title & help: print("Rock-papaer-scissors Game - By Hicham Labidi.\n- 'r' for rock.\n- 'p' for paper.\n- 'sc' for scissors.\n") # sets the variable wich stores whose turn it is, and the two boolean variables explained below. turn = 0 UserAgain = False BotAgain = False # defines the function that runs the game's starting events: def start(): isUserAgain = UserAgain isBotAgain = BotAgain # randomises the turn variable, so we have a random turn every time: turn = random.randint(1, 2) ''' what to do if someone's turn is the current one: ''' if turn == 1: ''' if it's the user's turn: ''' print("It's your turn!") # lets the user choose: user_choice = input("Choose either 'r', 'p' or 'sc': ") # for user: r - rock, p - paper, sc - scissors. bot_choice = random.randint(1, 3) # for bot: 1 - rock, 2 - paper, 3 - scissors. # print what bot choosed: if bot_choice == 1: print("Bot choosed 'rock'.") elif bot_choice == 2: print("Bot choosed 'paper'.") else: print("Bot choosed 'scissors'.") check(user_choice, bot_choice) else: ''' if it's the bot's turn: ''' print("It's bot's turn!") bot_choice = random.randint(1, 3) # for bot: 1 - rock, 2 - paper, 3 - scissors. # prints that the bot choosed something: print("Bot choosed something.") # lets the user choose: user_choice = input("Choose either 'r', 'p' or 'sc': ") # for user: r - rock, p - paper, sc - scissors. # prints what bot choosed: if bot_choice == 1: print("Bot choosed 'rock'.") elif bot_choice == 2: print("Bot choosed 'paper'.") else: print("Bot choosed 'scissors'.") check(bot=bot_choice, user=user_choice) # defines the function that checks who's the winner: def check(user, bot): if user == 'r' and bot == 3 or user == 'sc' and bot == 2 or user == 'p' and bot == 1: print("You win!\n") elif user == 'r' and bot == 2 or user == 'sc' and bot == 1 or user == 'p' and bot == 3: print("You lose!\n") elif user == 'r' and bot == 1 or user == 'p' and bot == 2 or user == 'sc' and bot == 3: print("Draw!\n") start() start()