我对编程很陌生,我很确定这个代码在这个网站上看起来很难看。这就是为什么我在这里。
我打赌你们很多人都有关于如何清理这些代码和/或提高效率的新手的精彩提示。请记住,我是一个认真的新程序员,如果它过于先进,它可能会超出我的想象。
import random
cscore = 0
pscore = 0
print 'I would like to play a game. \nThe name of the game is Rock, Paper, Scissors.'
rest = 'y'
while (rest == 'y'):
pick = ['r', 'p', 's']
b = (random.choice(pick))
a = raw_input ('\nFirst Letter ')
if a == 'r' or a == 'R':
a = 'Rock'
elif a == 'p' or a == 'P':
a = 'Paper'
elif a == 's' or a == 'S':
a = 'Scissors'
### assign name to computer's answer
if b == 'r':
b = 'Rock'
elif b == 'p':
b = 'Paper'
elif b == 's':
b = 'Scissors'
print 'You picked ' + a + '\nAnd I picked ' + b
##### compare picks
if a == 'Rock' and b == 'Rock':
print 'Silly, we both picked Rock, \nthat means we tied.'
elif a == 'Rock' and b == 'Paper':
print 'Yes! Paper smothers Rock, therefore, I win.'
cscore = cscore + 1
elif a == 'Rock' and b == 'Scissors':
print 'Crap, Rock smashes Scissors. You win.'
pscore = pscore + 1
elif a == 'Paper' and b == 'Paper':
print 'Silly, we both picked Paper, \nthat means we tied.'
elif a == 'Paper' and b == 'Scissors':
print 'Yes! Scissors cut Paper, therefore, I win.'
cscore = cscore + 1
elif a == 'Paper' and b == 'Rock':
print 'Crap, Paper smothers Rock. You win.'
pscore = pscore + 1
elif a == 'Scissors' and b == 'Scissors':
print 'Silly, we both picked Scissors, \nthat means we tied.'
elif a == 'Scissors' and b == 'Rock':
print 'Yes! Rock smashes Scissors, therefore, I win.'
cscore = cscore + 1
elif a == 'Scissors' and b == 'Paper':
print 'Crap, Scissors cut Paper. You win.'
pscore = pscore + 1
print '\nThe score is now Computer ' + str(cscore) + ' Human ' + str(pscore)
rest = raw_input ('\nWould you like to play again? y or n ')
print '\nThank you for playing. The final score was Computer ' + str(cscore) + ' Human ' + str(pscore)
if cscore > pscore:
print 'Ha!, I won and you lost.'
elif cscore == pscore:
print 'We tied in the overall score, you are a worthy opponent.'
elif cscore < pscore:
print 'You beat me, you low down mangy son of a gun. You must have cheated.'