Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Design a python program that simulates the game rock, paper, and scissors. You are to keep track of your wins, losses, and ties. You are to allow the users to play over and over again until he or she...

1 answer below »
Design a python program that simulates the game rock, paper, and scissors.  You are to keep track of your wins, losses, and ties.  You are to allow the users to play over and over again until he or she decides to quit.  After each throw, you will display the results of the throw followed by the cu
ent win, loss, tie numbers.  A throw consists of the player picking either Rock, Paper, or Scissors followed by the computer randomly choosing Rock, Paper, or Scissors.
Rules of the game:
Rock beats Scissors.
Paper beats Rock.
Scissor beats paper.
MENU:
1. Throw Rock
2. Throw Pape
3. Throw Scissors
4. Quit
Sample Run:
    Option 1:
    == RESULTS ==
Computer Throws Scissors, you win
Wins…………………...:        1
Losses………………...:     0
Ties…………………..:         0
Longest Win Streak....:     1
Longest Lose Streak..:     0
Note: After each Throw you will display the results from above
Answered 17 days After Jul 23, 2021

Solution

Pratyayee answered on Aug 10 2021
146 Votes
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Game_RockPaperScissors.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https:
localhost:8080/"
},
"id": "fnaLHw9Z2sXB",
"outputId": "f8c38a1c-19bc-46e6-d733-7469ab040eb3"
},
"source": [
"import random\n",
"import math\n",
" \n",
"def play():\n",
" user = input(\"\\n\\n What's your choice? 'r' for rock, 'p' for paper, 's' for scissors\\n\")\n",
" user = user.lower()\n",
" \n",
" computer = random.choice(['r', 'p', 's'])\n",
" \n",
" if user == computer:\n",
" return (0, user, computer)\n",
" \n",
" # r > s, s > p, p > r\n",
" if is_win(user, computer):\n",
" return (1, user, computer)\n",
" \n",
" return (-1, user, computer)\n",
" \n",
"def is_win(player, opponent):\n",
" # return true is the player beats the opponent\n",
" # winning conditions: r > s, s > p, p > r\n",
" if (player == 'r' and opponent == 's') or (player == 's' and opponent == 'p') or (player == 'p' and opponent == 'r'):\n",
" return True\n",
" return False\n",
" \n",
" \n",
"def play_best_of():\n",
" # play against the computer until player quits\n",
" \n",
" player_wins = 0\n",
" computer_wins = 0\n",
" tie = 0\n",
" \n",
" user1 = input(\"\\n Do you want to quit now? Type 'y' to quit, 'n' not to quit\\n\")\n",
" \n",
" \n",
" while user1 == 'n':\n",
" result, user, computer = play()\n",
" # tie\n",
" if result == 0:\n",
" tie += 1\n",
" print('It is a tie. You and the computer have both chosen {}. \\n\\n'.format(user))\n",
" print('No. of time player wins (cu
ent) : '+ str(player_wins))\n",
" print('No. of tie(cu
ent) : '+ str(tie))\n",
" print('No. of times the computer wins (cu
ent) : '+ str(computer_wins))\n",
" # you win\n",
" elif result == 1:\n",
" player_wins += 1\n",
" print('You chose {} and the computer chose {}. You won!\\n'.format(user, computer))\n",
" print('No. of time player wins (cu
ent) : '+ str(player_wins))\n",
" print('No. of...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here