Я пытаюсь сделать программу python для скалы, бумаги, ножниц, но я не могу заставить ее работать. Кто-нибудь может мне помочь? PS: Я использую Python 3.5Как работать рок, бумага, ножницы игра в Python
Я начинаю импортировать random
и говорить Python запускать различные программы в зависимости от результата от random.randint(1,3)
import random
def rps():
computer_choice = random.randint(1,3)
if computer_choice == 1:
computer_choice_rock()
elif computer_choice == 2:
computer_choice_paper()
elif computer_choice == 3:
computer_choice_scissors()
Я делаю программу он должен работать под этим текстом. Я думаю, что это может быть источником ошибок.
def computer_choice_rock():
use_choice = raw_input("1 for Rock, 2 for paper, 3 for Scissors: ")
if user_choice == "1":
print ("You Tie. You chose Rock, and the computer chose Rock.")
try_again()
if user_choice == "2":
print ("you win. You chose Paper, and the computer chose Rock.")
try_again()
if user_choice == "3":
print ("you lose. You chose Scissors, and the computer chose Rock.")
try_again()
else:
print ("try again")
computer_choice_rock()
def computer_choice_paper():
use_choice = raw_input("1 for Rock, 2 for paper, 3 for Scissors: ")
if user_choice == "1":
print ("you lose. You chose Rock, and the computer chose Paper.")
try_again()
if user_choice == "2":
print ("you tie. You chose Paper, and the computer chose Paper.")
try_again()
if user_choice == "3":
print ("you win. You chose Scissors, and the computer chose Paper.")
try_again()
else:
print ("try again")
computer_choice_paper()
def computer_choice_scissors():
use_choice = raw_input("1 for Rock, 2 for paper, 3 for Scissors: ")
if user_choice == "1":
print ("you win. You chose Rock, and the computer chose Scissors.")
try_again()
if user_choice == "2":
print ("you lose. You chose Paper, and the computer chose Scissors.")
try_again()
if user_choice == "3":
print ("you tie. You chose Scissors, and the computer chose Scissors.")
try_again()
else:
print ("try again")
computer_choice_rock()
def try_again():
choice = raw_input("Would you like to play again? y/n ")
if choice == "y" or choice == "yes" or choice =="Y" or choice == "Yes":
rps()
elif choice == "n":
print ("Thanks for playing")
quit()
else:
print ("Try again")
try_again()
rps()
Сообщение об ошибке:
Traceback (most recent call last):
File "C:/Users/Jakob/Desktop/rps.py", line 68, in <module>
rps()
File "C:/Users/Jakob/Desktop/rps.py", line 8, in rps
computer_choice_paper()
File "C:/Users/Jakob/Desktop/rps.py", line 28, in computer_choice_paper
user_choice = raw_input("1 for Rock, 2 for paper, 3 for Scissors: ")
NameError: name 'raw_input' is not defined
У вас есть опечатка: вы, вероятно, собираетесь назначить 'user_choice' (вместо' use_choice') 'raw_input()'. – edwinksl