Question

I already did the first part of my assignment but need help with the extra credit...

I already did the first part of my assignment but need help with the extra credit part of it

here is my code for the rock paper scissors game

RPS.py

import random

def main():
   print('ROCK PAPER SCISSORS ')
   print('Rules:')
   print(' 1) Rock wins over Scissors.')
   print(' 2) Scissors wins over Paper.')
   print(' 3) Paper wins over Rock.')
   print("\nR or r = Rock" + " \nP or p = Paper" + "\nS or s = Scissors" + "\nQ or q = Quit")


def rock_paper_scissors():
   guess = 'r','p','s'
   computer_score = 0
   person_score = 0
   tie=0
   rounds = 0
   p=0
   r=0
   s=0
   while True:
       rounds=rounds+1
       print("******************* ROUND #", rounds, "*******************")
       while True:
           rock_paper_scissors=input("Pick Your Weapon: [r]ock, [p]aper, or [s]cissors or [q]uit? ").lower()
      
           if rock_paper_scissors in ('r','p','s','q','R','P','S','Q'):
               break
           else:
               print('Enter a valid choice!')
  
       if rock_paper_scissors=='q':
           break
      
       if (p==0 and r==0 and s==0) or ( p==s and r==s):
           computer = random.choice(guess)
       elif p>r and p>s:
  
  
           computer = 'p'
       elif r>p and r>s:
           computer = 'r'
       elif s>p and s>r:
           computer = 's'
       elif s==p and s>r:
           computer=random.choice(('s','p'))
       elif s==r and s>p:
           computer=random.choice(('s','r'))
       elif r==p and r>s:
           computer=random.choice(('r','p'))
       else:
           pass
  
       if rock_paper_scissors == computer:
           print('Tie!')
           tie +=1
       if rock_paper_scissors=='p':
           p +=1
       if rock_paper_scissors=='r':
           r =r+1
       if rock_paper_scissors=='s':
           s +=1
       if (rock_paper_scissors == 'p' and computer == 'r'):
           print('Computer threw rock, you win!')
           person_score=person_score+1
           p +=1
       if (rock_paper_scissors == 'r' and computer == 's'):
           print('Computer threw scissors, you win!')
           person_score=person_score+1
           r +=1
       if(rock_paper_scissors == 's' and computer == 'p'):
           print('Computer threw paper, you win!')
           person_score=person_score+1
           s +=1
       if(rock_paper_scissors == 'r' and computer == 'p'):
           print('Computer threw paper, you lose!')
           computer_score=computer_score+1
           r +=1
       if (rock_paper_scissors == 's' and computer == 'r'):
           print('Computer threw rock, you lose!')
           computer_score=computer_score+1
           s +=1
       if(rock_paper_scissors == 'p' and computer == 's'):
           print('Computer threw scissors, you lose!')
           computer_score=computer_score+1
           p +=1
      
       print ("Your score:", person_score)
       print ("Computer's score:", computer_score)
       print("keep playing more rounds or for quit Enter q")

  
   print('The number of rounds the computer has won:',computer_score)
   print('The number of rounds the user has won:',person_score)
   print('The number of rounds that ended in a tie:',tie)
   print('\nThe number of times the user selected each weapon:')
   print('Rock:',r)
   print('Paper:',p)
   print('Scissors:',s)


main()
rock_paper_scissors()

AFTER you have finished RPS.py, create a new version RPSMaster.py. I will not review your source code before running and playing RPSMaster.py. After I play 15 rounds, if the score of the computer PLUS ties is 9 or greater, you’ll get an extra 20 points. This may require you to add additional logic, randomization or changing the original logic. Remember, I will be playing knowing what the original assignment was and what rules it should be following. I will use that against your program. How can you change the program to beat me?

I want to know how can i change my code to beat my teacher in a separate file RPSMaster.py

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import random

def main():
print('ROCK PAPER SCISSORS ')
print('Rules:')
print(' 1) Rock wins over Scissors.')
print(' 2) Scissors wins over Paper.')
print(' 3) Paper wins over Rock.')
print("\nR or r = Rock" + " \nP or p = Paper" + "\nS or s = Scissors" + "\nQ or q = Quit")


def rock_paper_scissors():
guess = 'r','p','s'
computer_score = 0
person_score = 0
tie=0
rounds = 0
p=0
r=0
s=0
while True:
rounds=rounds+1
print("******************* ROUND #", rounds, "*******************")
while True:
rock_paper_scissors=input("Pick Your Weapon: [r]ock, [p]aper, or [s]cissors or [q]uit? ").lower()
  
if rock_paper_scissors in ('r','p','s','q','R','P','S','Q'):
               if rock_paper_scissors=='p':
                   p +=1
               if rock_paper_scissors=='r':
                   r =r+1
               if rock_paper_scissors=='s':
                   s +=1
               break
else:
print('Enter a valid choice!')
  
if rock_paper_scissors=='q':
break
  
computer = random.choice(guess)
if p>r and p>s:
computer = 'p'
elif r>p and r>s:
computer = 'r'
elif s>p and s>r:
computer = 's'
elif s==p and s>r:
computer=random.choice(('s','p'))
elif s==r and s>p:
computer=random.choice(('s','r'))
elif r==p and r>s:
computer=random.choice(('r','p'))
else:
pass
  
if rock_paper_scissors == computer:
print('Tie!')
tie +=1
  
if (rock_paper_scissors == 'p' and computer == 'r'):
print('Computer threw rock, you win!')
person_score=person_score+1
p +=1
if (rock_paper_scissors == 'r' and computer == 's'):
print('Computer threw scissors, you win!')
person_score=person_score+1
r +=1
if(rock_paper_scissors == 's' and computer == 'p'):
print('Computer threw paper, you win!')
person_score=person_score+1
s +=1
if(rock_paper_scissors == 'r' and computer == 'p'):
print('Computer threw paper, you lose!')
computer_score=computer_score+1
r +=1
if (rock_paper_scissors == 's' and computer == 'r'):
print('Computer threw rock, you lose!')
computer_score=computer_score+1
s +=1
if(rock_paper_scissors == 'p' and computer == 's'):
print('Computer threw scissors, you lose!')
computer_score=computer_score+1
p +=1
  
print ("Your score:", person_score)
print ("Computer's score:", computer_score)
print("keep playing more rounds or for quit Enter q")

  
print('The number of rounds the computer has won:',computer_score)
print('The number of rounds the user has won:',person_score)
print('The number of rounds that ended in a tie:',tie)
print('\nThe number of times the user selected each weapon:')
print('Rock:',r)
print('Paper:',p)
print('Scissors:',s)


main()
rock_paper_scissors()

Add a comment
Know the answer?
Add Answer to:
I already did the first part of my assignment but need help with the extra credit...
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
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