Question: Attached to this assignment is a Python file containing a program. Currently, that program allows the user to play a game by entering a number
Attached to this assignment is a Python file containing a program. Currently, that program allows the user to play a game by entering a number to represent a word.
You are to edit this program so that the user must enter a word instead of a number representing the word. Once you make the change, add input validation to ensure the user only enters the correct words.
The program you are modifying can be found here: ProgrammingExercisestartFilepy
Requirements
This program is already well documented. Add appropriate comments to the top of the program and your additions that explain your edits.
The program must only accept the three approved wordsrock, paper, scissorsand must accomplish this using an input validation loop.
The program must be modified to provide the correct output now that the input has changed.
The program's filename must be changed to something appropriate.
You must write a sentence reflection in a block comment at the bottom of the program file after completing this project that includes your approach if you were successful in your edits. #RockPaperScissors
#logic from Starting Out with Programming Logic and Design by Tony Gaddis
#Written in Python and modified by Veronica Noone for academic purposes
#include random mod so we can have the computer make a choice
import random
#The getNumber module gets the users choice
def getNumber:
inputAnswerinput
Enter for rock, for paper, for scissors:
return intinputAnswer
#End Module
#The showWinner module display who wins calls whoWon function
def showWinnercomputer player:
print
Computer chose', whichChoicecomputer
printPlayer chose', whichChoiceplayer
if computer player:
printPlayer made same choice. Play again."
else:
which whoWoncomputer player
if which :
printComputer wins."
else:
if which :
printPlayer wins."
else:
printNo winner."
#end If
#end If
#end If
#End Module
#The whichChoice function displays choice
def whichChoicenumber:
if number :
return "rock"
elif number :
return "paper"
else:
return "scissors"
#end If
#End Function
#The whoWon function selects winner
def whoWoncomputer player:
# rock, paper, scissors
# rock smashes scissors
# scissors cuts paper
# paper wraps rock
# both choose same no winner
if computer player:
return
#end If
# test computer chose rock
if computer :
if player :
return #paper wraps rock
elif player :
return #rock smashes scissors
#end If
#end If
# test computer chose paper
if computer :
if player :
return #paper wraps rock
elif player :
return #scissors cuts paper
#end If
#end If
# test computer chose scissors
if computer :
if player :
return #rock smashes scissors
elif player :
return #scissors cuts paper
#end If
#end If
return
#End Function
# main module
def main:
# Get computer number
computer random.randint
#printcomputer #uncomment for debugging
# Get player number
playerNumgetNumber
# Show winner
showWinnercomputer playerNum
#End Module
print
printWelcome to RockPaperScissors with Python!"
print
againy
while againy:
main
againinput
play again? y or n
#end while
print
xinputThanks for playing! Click enter to exit"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
