Me ajudem com esse código em python por favor

2 respostas
python
4
# coding=utf-8


class point(object):
    def __init__(self,x,y):
        self.x=x
        self.y=y


class reward(point):
    def __init__(self,x,y,name):
        super(reward, self).__init__(x,y)
        self.name=name


class robo(point):
    def move_up(self):
        if self.y <10:
            self.y=self.y+1
        else:
            print("Movimento proibido")

    def move_down(self):
        if self.y >1:
            self.y=self.y-1
        else:
            print("Movimento proibido")

    def move_left(self):
        if self.x >1:
            self.x=self.x-1
        else:
            print("Movimento proibido")

    def move_right(self):
        if self.x<10:
            self.x= self.x+1
        else:
            print("Movientno proibido")



def check_reward(robo,reward):
    for reward in rewards:
        if robo.x== reward.x and robo.y==reward.y:
            print("O robo achou a recompensa {}" .format(reward.name))


import random

r1= reward(random.randint(1,10) , random.randint(1,10), "moeda")
r2= reward(random.randint(1,10), random.randint(1,10), "Gasolina")
r3= reward(random.randint(1,10), random.randint(1,10) , "arma")

rewards = (r1,r2,r3)

robo1= robo(random.randint(1,10), random.randint(1,10))

for i in range(10):
    moviment= input("digite move, down, left ou right")
    if moviment == 'up':
        robo1.move_up()
    elif moviment == 'down':
        robo1.move_down()
    elif moviment == 'left':
        robo1.move_left()
    elif moviment == 'right':
        robo1.move_right()

    else:
        print("Movimento inválido")
        continue

    check_reward(robo1,rewards)

O erro é:

/usr/bin/python2.7 /home/vitor/PycharmProjects/JogoDoRobo/principal.py
digite move, down, left ou right up
Traceback (most recent call last):
File “/home/vitor/PycharmProjects/JogoDoRobo/principal.py”, line 60, in
moviment= input(“digite move, down, left ou right”)
File “”, line 1, in
NameError: name ‘up’ is not defined

2 Respostas

rodevops

Em python 2.7 troque o input por raw_input para ver se resolve.

input é válido para python 3

Obs: Evite termos como socorro, ajuda, me ajude por favor, essas coisas, siga as boas práticas do fórum.

Obs 2: aprenda a ler as mensagens de erro e pesquisar mais a respeito antes de postar tópico, use o fórum como último recurso

4

Cara, obrigado. Funcionou

Criado 26 de outubro de 2018
Ultima resposta 26 de out. de 2018
Respostas 2
Participantes 2