I recently bought a book for beginners transitioning into python programming. The book is called "Computer Programming and Cyber Security for Beginners Python by Manuel McFeely." I am not sure how well this book was checked for code errors but one of the sample codes provided does not work. Here is the code below:
"""Rock Paper Scissors
-
"""
import random
import os
import re
os.system('cls' if os.name=='nt' else 'clear')
while (1 \< 2):
print("\\n")
print("Rock, Paper, Scissors - Shoot!")
userChoice = raw_input("Choose your weapon \[R\]ock, \[P\]aper, or \[S\]cissors: ")
if not re.match("\[SsRrPp\]", userChoice):
print("Please choose a letter:")
print("\[R\]ock, \[S\]cissors or \[P\]aper.")
continue
#Echo the user's choice
print("You choose: " + userChoice)
choices = \['R', 'P', 'S'\]
opponenetChoice = random.choice(choices)
print("I chose: " + opponenetChoice)
if opponenetChoice == str.upper(userChoice):
print("Tie!")
\#if opponenetChoice == str("R") and str.upper(userChoice) == "P":
elif opponenetChoice == 'R' and userChoice.upper() == 'S':
print("Scissors beats rock, I win! ")
continue
elif opponenetChoice == 'S' and userChoice.upper() == 'P':
print("Scissors beats paper, I win!")
continue
elif opponenetChoice == 'P' and userChoice.upper() == 'R':
print("Paper beats rock, I win! ")
continue
else:
print("You win!")
Here is an image of the source code:
When checking out this sample code, I typed in verbatim the sample code that was provided and tried running the module with no success. When ran, this was the error
Rock, Paper, Scissors - Shoot!
Traceback (most recent call last):
File "C:\\Users\\parke\\AppData\\Local\\Programs\\Python\\Python310_Training\\Python_McFeely\\Rock Paper Scissors.py", line 11, in \<module\>
userChoice = raw_input("Choose your weapon \[R\]ock, \[P\]aper, or \[S\]cissors: ")
NameError: name 'raw_input' is not defined