Question

Create a python program to play rock paper scissors using a while loop and if statements....

Create a python program to play rock paper scissors using a while loop and if statements. I have started but have gotten stuck in a continuous loop. Please look over my code and help me find where I went wrong. Here it is:

import random

#Choice
weapons=['Rock' ,'Paper' ,'Scissors']

print('Rock, Paper, Scissors!')
print('Rock, Paper, Scissors!')
print('Shoot!')
human=input('Choose Rock, Paper, Scissors, or Quit! ')
print('')#Blank Line
while human != 'Quit':
human_choice=human
computer=random.choice(weapons)
print(computer)
if human==computer:
print("It's a tie!")
elif human=='Rock':
if computer=='scissors':
print('You Win!')
else:
print('Computer Wins')
elif human=='Paper':
if computer=='Rock':
print('You Win!')
else:
print('Computer Wins!')
elif human=='Scissors':
if computer=='Paper':
print('You Win!')
else:
print('Computer Wins!')
else:
human=input('Choose Rock, Paper, Scissors, or Quit! ')


0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question, your code is okay but the entire code can be condensed into few lines of code. I have commented so that you can follow the code. 

Let me know if you still have any doubts or question. Follow the screenshot for identation and sample output.

If you are satisifed, please please do up vote.

thank you !

==============================================================================

import random
weapons=['Rock' ,'Paper' ,'Scissors']

print('Rock, Paper, Scissors!')
print('Rock, Paper, Scissors!')
print('Shoot!')

print('')#Blank Line
while True:
              # covert input to title case
    human= input('Enter choice: Rock, Paper, Scissors ( quit to end): ').title() 
    if human=='Quit':
        print('Goodbye!. Thanks for playing.')
        break
    if human in weapons: # check user input in the list for validation
        computer = random.choice(weapons) 
        print('You choose {}, Computer choose {}'.format(human,computer))
        if human=='Rock' and computer=='Scissors': # first win condition
            print('You win!')
        elif human=='Paper' and computer=='Rock':  # second win condition
            print('You win!')
        elif human =='Scissors' and computer=='Paper': # third win condition
            print('You win!')
        elif human==computer: # condiiton when both are same
            print('Its a tie!')
        else: # for all other conditions computer wins
            print('Computer wins')
    else: # when user types incorrect input eg spelling mistakes or blank input
        print('Invalid choice.')

=======================================================================

import random weaponsRock 1 Paper Scissors 1 print Rock, Paper, Scissors!) print Rock, Paper, Scissors!) print Shoot!

if human-=Quit: 11 print (Goodbye!. Thanks for playing. ) 12 break 13 if human in weapons: 14 computer random. choice (we

Add a comment
Know the answer?
Add Answer to:
Create a python program to play rock paper scissors using a while loop and if statements....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember...

    Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember the rules: 1. Rock beats scissors 2. Scissors beats paper 3. Paper beats rock The program should ask the users for their names, then ask them for their picks (rock, paper or scissors). After that, the program should print the winner's name. Note, the players may pick the same thing, in this case the program should say it's tie. when the user input an...

  • Rock, Paper, Scissors - Write a MATLAB script file to play Rock, Paper, Scissors with the...

    Rock, Paper, Scissors - Write a MATLAB script file to play Rock, Paper, Scissors with the computer. x=rand; if x< 1/3 then it is Rock, if l/3<= x < 2/3 it is Paper else it is Scissors end if This is how the game should look like on the screen: Enter "r" for Rock, "p" for Paper, or "s" for Scissors", or enter "q" to Quit the game r leftarrow say, this is what you entered Computer choice: Scissors RESULT:...

  • Write a computer game based on rock-paper- scissors in C++. The 2-player game will be interactive:...

    Write a computer game based on rock-paper- scissors in C++. The 2-player game will be interactive: human vs. computer! Making the game interactive presents a new issue for us -- how do we get the computer&#39;s choice? To solve this, we will use a &quot;random number generator&quot;, which is the basis for all computer gaming. This enables the properly programmed computer to act like it is actually &quot;thinking&quot; and making its own decisions. This is the largest, most involved program...

  • Write a Python program (using python 3.7.2) that lets the user play the game of Rock,...

    Write a Python program (using python 3.7.2) that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Don’t display the...

  • Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game...

    Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game in Python 3 that a user plays against the computer with the ability to save and load a game and its associated play statistics. Purpose: The purpose of this challenge is to assess the developer’s ability to create an interactive application with data persistence in Python 3. Requirements: Create a Rock, Paper, Scissors game in Python named rps.py according to the requirements specified in...

  • java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of...

    java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of the common game Rock Paper Scissors that is often used to pass time (or sometimes to make decisions.) The rules of the game are outlined below: • • Scissors cuts Paper Paper covers Rock Rock crushes Lizard Lizard poisons Spock Spock smashes Scissors Scissors decapitates Lizard Lizard eats Paper Paper disproves Spock Spock vaporizes Rock Rock crushes Scissors Write a program that simulates the...

  • Rock, Paper, Scissors (also known by several other names, see http://en.wikipedia.org/wiki/Rock p...

    Help needed in Perl language program! Note : Perl Language Rock, Paper, Scissors (also known by several other names, see http://en.wikipedia.org/wiki/Rock paper scissors) is an extremely popular hand game most often played by children. Often, it is used as a method of selection similar to flipping a coin or throwing dice to randomly select a person for some purpose. Of course, this game is not truly random since a skilled player can often recognize and exploit the non-random behavior of...

  • For this week’s assignment, we will be recreating the Rock, Paper, Scissors program using Object-...

    For this week’s assignment, we will be recreating the Rock, Paper, Scissors program using Object-Oriented Programming. You will be working with me on a team to build the program. I have already written my part of the program, and the Game.java file is attached. Your task will be to write a RockPaperScissors class that contains the following methods: getUserChoice: Has the user choose Rock, Paper, or Scissors. After validating the input, the method returns a String containing the user choice....

  • 5.12 A5 Program Do you want to play. a. game? The Big Bang Theory fans may...

    5.12 A5 Program Do you want to play. a. game? The Big Bang Theory fans may recognize Rock Paper Scissors Lizard Spock as a game of chance that expands on the standard Rock Paper Scissors game. It introduces two new hand signs and several more rules. The rules: • Scissors cuts Paper • Paper covers Rock • Rock crushes Lizard • Lizard poisons Spock • Spock smashes Scissors • Scissors decapitates Lizard • Lizard eats Paper • Paper disproves Spock...

  • In this problem, you’ll play a simple rock, paper, scissors game. First, you’ll ask the user...

    In this problem, you’ll play a simple rock, paper, scissors game. First, you’ll ask the user to pick rock, paper, or scissors. Then, you’ll have the computer randomly choose one of the options. After that, print out the winner! You should keep playing the game until the user hits enter. Note: You’ll need to implement a method called String getWinner(String user, String computer). Luckily, you just wrote that in an earlier program! Here is a sample run of the program....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT