0
과제의이 부분에 문제가 있습니다. 게임의 승자를 선언하고 함수에 입력해야합니다. if 문을 모두 입력하면 함수 def playGame()
을 만들어야합니다. 여기에는 다음을 포함해야합니다.게임에서 기능 구현
showRules()
user = getUserChoice()
computer = getComputerChoice()
declareWinner(user, computer)
어떻게해야할지 모르겠습니다. 도와주세요. 다음은
은 지금까지 완료 한 코드입니다 : (나는 경우 가위 문뿐만 아니라 할 필요가시겠습니까?)#Display game rules
print("Rules: Each player chooses either Rock, Paper, or Scissors.")
print("\tThe winner is determined by the following rules:")
print("\t\tScissors cuts Paper --> Scissors wins")
print("\t\tPaper covers Rock --> Paper wins")
print("\t\tRock smashes Scissors --> Rock Wins")
def userchoice():
choice = (input("Make your selection (Rock, Paper, or Scissors). ")).lower()
return choice
#obtain computer input
def getComputerchoice():
import random
rnum = random.randint(1,3)
if rnum == 1:
print("The computer has chosen Rock.")
if rnum == 2:
print("The computer has chosen Paper.")
if rnum == 3:
print("The computer has chosen Scissors.")
return rnum
#Declare winner
def declarewinner (user, rnum):
if userchoice == 1:
print("You have chosen rock.")
if getComputerchoice == 1:
print("Computer has chose rock as well.")
return 0
else:
print("The computer has chosen scissors. Rock breaks scissors. You WIN!")
return 1
if userchoice == 2:
print("You have chosen paper.")
if getComputerchoice == 1:
print("The computer has chosen rock. Paper covers rock. You WIN!")
return 1
elif getComputerchoice == 2:
print("The computer has chosen paper as well.")
return 0
else:
print("The computer has chosen scissors. Scissors cut paper. You LOSE!")
return 1
if userchoice == 3:
print("You have chosen scissors")
if getComputerchoice == 1:
print("The computer has chosen rock. Rock breaks scissors. You LOSE!")
return 1
elif getComputerchoice == 2:
print("The computer has chosen paper. Scissors cut paper. You WIN!")
return 1
기능 그것들은 본질적으로 I/O로서의 역할을합니다. 즉, 입력 (또는'void')과 리턴 값 (또는'void')만을 받아야한다는 것을 의미합니다. 함수의 결과에 따라 다음 주요 동작을 결정할 수 있습니다. 작성하는 모든 함수에서 인쇄를 시작하면 응용 프로그램에 대한 모든 제어 권한을 잃을 수 있습니다. 매우 드문 경우에만 함수 내부에서 인쇄해야합니다 (주로 오류 또는 로깅에서만 사용). –
첫째, 현재 기능이 모두 올바르게 작동하는지 확인해야합니다. 규칙 인쇄를 적절히 명명 된 함수에 캡슐화하지 않은 경우 사용자가 문자열을 선택하지만 정수를 테스트하면 컴퓨터는 '3'또는 '없음'만 선택하고'declarewinner '의 들여 쓰기는 검토해야합니다. – jonrsharpe