0
나는 바위, 종이 또는 가위를 연주하도록 선택할 수있는 프로그램을 만들려고합니다. 일단 그들이 무엇을하고 싶은지와 그들이하고 싶은 게임의 양을 선택하면, 그들이이기 든 잃든 지 말하게됩니다.가위 바위 가위 결과
나는 그들이 얻거나 잃은 시간을 계산하려고하지만 대신 각 라운드 후에 인쇄합니다. 게임이 끝난 후 인쇄 할 수있는 방법이 있습니까? 내가
from random import randint
def main():
games = int(input("How many games would you like to play?"))
while games > 0:
games -= 1
comp = computer()
choice = user()
print("You played", choice, "and the computer played", comp)
winner(comp, choice)
def computer():
comp = randint in range (0,3)
if comp == 0:
comp = 'rock'
elif comp == 1:
comp = 'paper'
elif comp == 2:
comp = 'scissors'
return comp
def user():
choice = int(input("choose 0 for rock, 1 for paper, or 2 for scissors: "))
if choice == 0:
choice = 'rock'
elif choice == 1:
choice = 'paper'
elif choice == 2:
choice = 'scissors'
else:
print("invalid input")
return choice
def winner(comp, choice):
tie = 0
win = 0
lose = 0
while True:
if choice == "rock" and comp == "rock":
result = 'tie'
tie += 1
break
elif choice == 'rock'and comp == 'scissors':
result = "you win"
win += 1
break
elif choice == 'rock' and comp == 'paper':
result = "you lose"
lose += 1
break
elif choice == 'paper' and comp == 'paper':
result = 'tie'
tie += 1
break
elif choice == 'paper' and comp == 'scissors':
result = 'you lose'
lose += 1
break
elif choice == 'paper' and comp == 'rock':
result = 'you win'
win =+ 1
break
elif choice == 'scissors' and comp == 'scissors':
result = 'tie'
tie += 1
break
elif choice == 'scissors' and comp == 'paper':
result = 'you win'
win += 1
break
elif choice == 'scissors' and comp == 'rock':
result = 'you lose'
lose +=1
break
else:
print("error")
break
print(result)
print("you won", win,"times, and lost", lose,"times, and tied", tie,"times.")
main()
이러한 질문은 모두 과제에서 비롯된 것입니까? – roelofs
유용 할 경우 대답을 수락하는 것이 예의라는 것을 기억하십시오 ... – roelofs
예. 당신이 그 일을 할 수 있다는 것을 깨닫지 못했습니다. – savannah