私はPythonを初めて使用し、いくつかのプログラムを作成しただけです。これが私がじゃんけんゲームのために書いた最近のコードです。私はすでにそれをテストしました、そしてそれは素晴らしい働きをします。単純化する方法はありますか?ありがとう!
import random
wins=0
losses=0
ties=0
rounds=0
r=1 #rock
p=2 #paper
s=3 #scissors
y = "The computer has made its choice, how about you?"
while rounds <= 10:
print y
x = input('(1)rock, (2)paper, or (3)scissors? :')
choice = x
cpu_choice= random.randint(1, 3)
if (choice, cpu_choice) == (1, 2):
rounds += 1
losses += 1
print 'computer chose paper, you lose'
elif (choice, cpu_choice) == (3, 2):
print 'you win'
rounds += 1
wins += 1
elif (choice, cpu_choice) == (2, 2):
print 'TIE!'
rounds += 1
ties += 1
elif (choice, cpu_choice) == (1, 3):
print 'you win'
rounds += 1
wins += 1
elif (choice, cpu_choice) == (3, 3):
print 'TIE!'
rounds += 1
ties += 1
elif (choice, cpu_choice) == (2, 3):
print 'computer chose scissors, you lose'
rounds += 1
losses += 1
elif (choice, cpu_choice) == (1, 1):
print 'TIE'
rounds += 1
ties += 1
elif (choice, cpu_choice) == (3, 1):
print 'computer chose rock, you lose'
rounds += 1
losses += 1
elif (choice, cpu_choice) == (2, 1):
print 'you win'
rounds += 1
wins += 1
else:
print 'Please choose 1, 2, or 3'
print 'Game Over'
if wins>losses:
print 'YOU WON'
print 'wins:' , wins
print 'losses' , losses
print 'ties' , ties
else:
print 'you lose'
print 'wins:' , wins
print 'losses:' , losses
print 'ties:' , ties