Rock Paper Scissor Python

时间:2016-04-05 18:07:42

标签: python

我学习Python并编写摇滚,纸张和剪刀游戏。

我在Ubuntu中使用IDLE。代码编译得很好,但我仍然无法运行。 IDLE在这个系统中正常运行。请帮我解决这个问题。

提前致谢

#!/usr/bin/env python2
import time
import random

rock = 1
paper = 2
scissors = 3

names = {rock:"rock", paper:"Paper",scissors: "Scissors"}
rules = {rock: scissors, paper: rock,scissors: paper}

player_score = 0
computer_score = 0



def start():
    print "Start"
    while game():
     pass
    scores()

def game():
    player = move()
    computer = random.randint(1,3)
    result(player,computer)
    return play_again()
def move():
    while True:
        print
        player = raw_input("Rock = 1 paper = 2 scissor = 3")
        try:
            player = int(player)
            if player in (1,2,3):
                return player
        except ValueError:
                pass
        print "Enter number"

def result(player,computer):
    print "Computer threw {0}!".format(names[computer])
    if player == computer:
     print ("Tie")
    else:
     if rules(player) == computer:
        print("You win")
        player_score += 1

     else:
        print("Computer wins")
        computer_score += 1
def play_again():
    answer = raw_input("Play Again")
    if answer in ("y" "Y"):
      return answer
    else:
        print ("Thanks")

def scores():
    global player_score, computer_score
    print "Player", player_score
    print "Computer", computer_score

    start()

1 个答案:

答案 0 :(得分:0)

Dedent最后一行,start()。解释器运行脚本的上层,但缩进使该行成为函数score()的一部分。