이것을 실행할 때마다 25 ~ 50 % 정도 작동 할 것이고 그 이유를 알 수 없습니다. 이전에는 if 문에 문제가 있었지만 잊어 버린 쉬운 수정 이었지만 실제로 작동하기 때문에 당황 스러웠습니다. 그런데이 코드는 repl.it에서 만들어지고 실행되었습니다. 편집 : rng 변수를 인쇄하는 부분을 끝에 추가했는데 typeError : 'str'pbject is not callable
import random
rng=(random.randint(1,3))
player=input("rock, paper, or scissors ")
if player=="rock":
if rng==1:
print("paper covers your rock")
elif rng==2:
print=("both rock, tie")
elif rng==3:
print("your rock crushes scissors")
else:
print("error")
elif player=="paper":
if rng==1:
print("both paper, tie")
elif rng==2:
print=("your paper covers rock")
elif rng==3:
print("scisors cut your paper")
else:
print("error")
elif player=="scissors":
if rng==1:
print("your scissors cut paper")
elif rng==2:
print=("rock crushes your scissors")
elif rng==3:
print("both scissors, tie")
else:
print("error")
else:
print("error")
이 줄에서 :
print=("rock crushes your scissors")
이 =
값을 무시한다 print
함수 대신 문자열로 돌려. 이로 인해 인쇄 문이 인쇄되지 않습니다!
따라서 =
표시를 제거 하십시오. 이 오타는 @ chitown88이 지적한 것처럼 실제로 코드에 세 번 나타납니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다