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: 07ProgrammingExercise08_(s)tartFile.py
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 words-rock, paper, scissors-and 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 4-5 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():
inputAnswer=input("
Enter 1 for rock, 2 for paper, 3 for scissors: ")
return int(inputAnswer)
#End Module
#The showWinner module display who wins -- calls whoWon function
def showWinner(computer, player):
print('
Computer chose', whichChoice(computer))
print('Player chose', whichChoice(player),'
')
if computer == player:
print("Player made same choice. Play again.")
else:
which = whoWon(computer, player)
if which ==1:
print("Computer wins.")
else:
if which ==2:
print("Player wins.")
else:
print("No winner.")
#end If
#end If
#end If
#End Module
#The whichChoice function displays choice
def whichChoice(number):
if number ==1:
return "rock"
elif number ==2:
return "paper"
else:
return "scissors"
#end If
#End Function
#The whoWon function selects winner
def whoWon(computer, player):
# 1= rock, 2= paper, 3= scissors
# rock smashes scissors
# scissors cuts paper
# paper wraps rock
# both choose same no winner
if computer == player:
return 0
#end If
# test computer chose rock
if computer ==1:
if player ==2:
return 2 #paper wraps rock
elif player ==3:
return 1 #rock smashes scissors
#end If
#end If
# test computer chose paper
if computer ==2:
if player ==1:
return 1 #paper wraps rock
elif player ==3:
return 2 #scissors cuts paper
#end If
#end If
# test computer chose scissors
if computer ==3:
if player ==1:
return 2 #rock smashes scissors
elif player ==2:
return 1 #scissors cuts paper
#end If
#end If
return 0
#End Function
# main module
def main():
# Get computer number
computer = random.randint(1,3)
#print(computer) #uncomment for debugging
# Get player number
playerNum=getNumber()
# Show winner
showWinner(computer, playerNum)
#End Module
print("-------------------------------------------")
print("Welcome to Rock-Paper-Scissors with Python!")
print("-------------------------------------------")
again="y"
while again=="y":
main()
again=input('
play again? y or n ')
#end while
print("
-------------------------------------------")
x=input("Thanks for playing! Click enter to exit")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!