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
  • I need the create a Python code that makes a two-player Rock-Paper-Scissors game. (Hint: Ask for...

    I need the create a Python code that makes a two-player Rock-Paper-Scissors game. (Hint: Ask for player plays (using input), compare them, print out a message of congratulations to the winner, and ask if the players want to start a new game) Please help me see why my "continue" is asking the players to start a new game. Here is my code; user1= input("Whats your name? ") user2= input("And your name? ") a = input("%s, do yo want to choose...

  • Python Language: Please see program listed below of a game called: Rock, Paper, Scissors. Please add...

    Python Language: Please see program listed below of a game called: Rock, Paper, Scissors. Please add an exception, for example if the user inputs something else other than rock, paper or scissors, the exception will print message: "Enter only rock, paper, or scissors". Also add option to keep playing the game, for example: print: "Would you like to play again? Enter Y or N". If the user says Y, the game will repeat, if N, the game will end and...

  • This program should be in c++. Rock Paper Scissors: This game is played by children and...

    This program should be in c++. Rock Paper Scissors: This game is played by children and adults and is popular all over the world. Apart from being a game played to pass time, the game is usually played in situations where something has to be chosen. It is similar in that way to other games like flipping the coin, throwing dice or drawing straws. There is no room for cheating or for knowing what the other person is going to...

  • 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...

  • Write a program in python that lets the user play the game Rock, Paper, Scissors against...

    Write a program in python that lets the user play the game Rock, Paper, Scissors against the computer. The program should work as follows: 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. 2 corresponds to paper, and 3 corresponds to scissors. To set up the random number library, write the following at the top of your code: import random random.seed(300) Use...

  • 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...

  • JAVA Beginnings of a paper-rock-scissors game. Paper-rock-scissors is a game often used to make decisions. There...

    JAVA Beginnings of a paper-rock-scissors game. Paper-rock-scissors is a game often used to make decisions. There are two players. Each player secretly chooses either, paper, rock or scissors. At the count of three, each player reveals what they have chosen. The winner of the game is determined this way: paper beats rock (because paper covers rock) rock beats scissors (because rock crushes scissors) scissors beat paper (because scissors cut paper) If the two players choose the same item, it is...

  • 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...

  • C++ Write a program that plays the rock, paper, scissors game. Rock beats scissors; scissors beats...

    C++ Write a program that plays the rock, paper, scissors game. Rock beats scissors; scissors beats paper; paper beats rock. You must use these specific functions in your program. These are the prototypes: char generateP2toss(); int checkThrow(char, char); void printStatistics(int, int, int, int); void finalStatistics(int, int, int, int); void welcome(); Notes on these functions: generateP2toss() will generate the computer's toss (the computer is player2). It returns either an "r", "p", or "s/" checkThrow(char char) will check the throw by passing...

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