我是python编程的初学者&从在线学习基础知识。下面的代码如在线视频教程中所示,但在我的机器中运行时会给出空白输出。我使用的是python 2.7.14版本。在Sublime编辑器中编写代码并使用cmd运行该文件。我有一些其他代码运行得非常好。
我想知道以下代码有什么问题,因为它没有打印所需的行/空白。
def main():
x, y = 10, 100
if (x < y):
st = "x is less than y"
elif (x == y):
st = "x and y are same"
else:
st = "x is greater than y"
print (st)
答案 0 :(得分:1)
你必须调用函数main()
:
def main():
x, y = 10, 100
if (x < y):
st = "x is less than y"
elif (x == y):
st = "x and y are same"
else:
st = "x is greater than y"
print(st)
main()
输出:
x is less than y