【问题标题】:Im new to python and I cant seem to use "else" [duplicate]我是 python 新手,我似乎不能使用“else”[重复]
【发布时间】:2014-12-24 02:08:16
【问题描述】:

所以在 python 的新手中,我正在学习 A 级计算,我们要学习的语言是 python。 我真的很落后,我什么都不知道。尽管已经是 2 个学期,距离考试期仅剩 4/5 个月。 所以我一直在看一个视频教程,由于某种原因我不能使用“其他” ![这里是教程做的,我都复制出来了][1]

这是本教程所做的:

sister_age = 15

brother_age = 12

if sister_age > brother_age:


 print" "sister is older"

else:

   print "brother is older"

这个结果就是“姐姐年纪大了

但是我把它复制出来了:

sister_age=15

 brother_age=12

 if sister_age>brother_age:

print("sister is older")

   else:

然后出现一条错误消息,内容如下:

"SyntaxError: unindent 不匹配任何外部缩进级别"

对不起,我就是不明白。 非常感谢,您有时间阅读本文。

【问题讨论】:

  • 尝试缩进你的代码
  • 只是为了说明清楚:在 Python 中,缩进不是装饰性的,它是语法的一部分,用于在条件(if/else)、循环、 try/except,函数和类定义等

标签: python


【解决方案1】:

缩进是关键。

sister_age = 15
brother_age = 12
if sister_age > brother_age:
    print "sister is older"
else:
    print "brother is older"

【讨论】:

    猜你喜欢
    • 2017-03-27
    • 2021-08-08
    • 1970-01-01
    • 2015-10-19
    • 2017-09-20
    • 1970-01-01
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多