Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def rps(player_choice):
- '''Basic rock paper scissors game
- returns a list a boolean to see if winning as first list element
- and the bot choice as second arguement'''
- choices = ["rock", "paper", "scissors"]
- player_wins = False
- player_choice = player_choice.lower()
- if player_choice not in choices:
- return [False, ""]
- bot_choice = random.choice(choices)
- if bot_choice == player_choice:
- player_wins = False
- elif bot_choice == "rock" and player_choice == "scissors":
- player_wins = False
- elif bot_choice == "rock" and player_choice == "paper":
- player_wins = True
- elif bot_choice == "paper" and player_choice == "rock":
- players_wins = False
- elif bot_choice == "paper" and player_choice == "scissors":
- player_wins = True
- elif bot_choice == "scissors" and player_choice == "rock":
- player_wins = True
- else:
- player_wins = False
- return [player_wins, bot_choice]
- def main():
- running = True
- while running:
- game = rps(raw_input("rock paper scissors > "))
- if game[0]:
- print("You won the bot choose %s" % game[1])
- else:
- print("You lose the bot choose %s" % game[1])
- if raw_input("Would you like to play again? ").lower() not in "okayes":
- running = False
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement