首页 > 解决方案 > 我的 Python 2.7 代码中有语法错误。我需要帮助

问题描述

每当我运行它时,它都会给我这个语法错误:

File "main.py", line 27
decide_winner (user_choice, computer_choice) 
^
IntendationError: unexpected indent

我不知道如何解决这个问题,我已经研究了大约两天了,我真的是专家的帮助。

from random import randint
options = ['ROCK','PAPER','SCISSORS']
message = {"tie': 'you've tied",
          "won': 'you've won!",
          "lost': 'you've lost!"
          }
def decide_winner(user_choice, computer_choice):
  print 'you chose %s' % user_choice
  print 'computer chose %s' % computer_choice
  if user_choice == computer_choice:
    print message['tie']
  elif user_choice == options[0] and computer_choice == options[2]:
    print message['won']
  elif user_choice == options[1] and computer_choice == options[0]:
    print message['won']
  elif user_choice == options[2] and computer_choice == options[1]:
    print message['won']
  else:
    print message['lost']
def play_RPS():
  user_choice = raw_input('Enter ROCK PAPER or SCISSORS')
  user_choice = user_choice.upper()
  computer_choice = options[randint(0,2)]
    decide_winner(user_choice, computer_choice)         
play_RPS()

标签: python-2.7

解决方案


推荐阅读