鱼C论坛

 找回密码
 立即注册
查看: 2523|回复: 2

[已解决]python代码对齐问题

[复制链接]
发表于 2017-6-8 09:14:24 | 显示全部楼层 |阅读模式

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

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

x
可能是个老问题。但自己修改了,怎么都不对。<零基础入门学python>中110面的代码例子:
import random as r

class Fish:
        def __init__(self):
              self.x = r.randint(0,10)
              self.y = r.randint(0,10)

        def move(self):
               self.x = -1
               print("我的位置是:",self.x , self.y)

class Goldfish(Fish):
                pass

class Carp(Fish):
                pass

class Salmon(Fish):
                pass

class Shark(Fish):
         def __init__(self):
                self.hugry = True
               
        def eat(self):   //这行提示:unindent does not match any outer indentation leve.
               if self.hungry = False
                        print("吃货的梦想:")
                        self.hungry =  False
                else:
                        print("太撑了!")
错误截图如下:
    C:\Users\Administrator\Desktop\1.png
我在网上也查了,说是没有对齐。我重新都用tab对齐,但是还是这行有错。要问下,怎么检查修改?在python中对齐有这么麻烦么?win7系统,python3.52
最佳答案
2017-6-8 09:18:59
import random as r

class Fish:
        def __init__(self):
              self.x = r.randint(0,10)
              self.y = r.randint(0,10)

        def move(self):
               self.x = -1
               print("我的位置是:",self.x , self.y)

class Goldfish(Fish):
                pass

class Carp(Fish):
                pass

class Salmon(Fish):
                pass

class Shark(Fish):
         def __init__(self):
                self.hugry = True
               
         def eat(self):   #这行提示:unindent does not match any outer indentation leve.
                if self.hungry == False:
                        print("吃货的梦想:")
                        self.hungry =  False
                else:
                        print("太撑了!")

自己对照下
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-6-8 09:18:59 | 显示全部楼层    本楼为最佳答案   
import random as r

class Fish:
        def __init__(self):
              self.x = r.randint(0,10)
              self.y = r.randint(0,10)

        def move(self):
               self.x = -1
               print("我的位置是:",self.x , self.y)

class Goldfish(Fish):
                pass

class Carp(Fish):
                pass

class Salmon(Fish):
                pass

class Shark(Fish):
         def __init__(self):
                self.hugry = True
               
         def eat(self):   #这行提示:unindent does not match any outer indentation leve.
                if self.hungry == False:
                        print("吃货的梦想:")
                        self.hungry =  False
                else:
                        print("太撑了!")

自己对照下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-6-8 10:38:54 | 显示全部楼层
scalper 发表于 2017-6-8 09:18
import random as r

class Fish:

非常感谢!对照了下,发砚是判断写成了赋值。感谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-2-27 23:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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