鱼C论坛

 找回密码
 立即注册
查看: 426|回复: 1

我不明白我錯在哪裡?? 新手多包涵~~

[复制链接]
发表于 2018-10-3 00:59:47 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import random as r

class turtle:
   
    體力=100
    if 體力>100:
        print('體力=100')
   
    def _init_(self):
        self.x=r.randint(0,10)
        self.y=r.randint(0,10)

    def move(self):
        self.x -= 1 or self.x += 1 or self.x -= 2 or self.x += 2 or self.y -= 1 or self.y += 1 or self.y -= 2 or self.y += 2
        print('我現在的位置',self.x,self.y)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-10-3 02:12:21 | 显示全部楼层
self.x -= 1 or self.x += 1 or self.x -= 2 or self.x += 2 or self.y -= 1 or self.y += 1 or self.y -= 2 or self.y += 2
Python里没有这种写法,而且初始化方法__init__(self)里的下划线是双下划綫。
import random as r

class Turtle:  #  类名最好首字母大写

    def __init__(self):  #  双下划綫
         self.power = 100 # 应避免用中文命名变量
         self.x=r.randint(0,10)
         self.y=r.randint(0,10)

    def move(self):
        self.x = self.x + r.choice([-1, 1])
        self.y = self.y + r.choice([-1, 1])
        print('我現在的位置',(self.x,self.y))
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-7 11:26

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表