【问题标题】:Python coding exercisePython编码练习
【发布时间】:2017-01-11 06:50:19
【问题描述】:

我有一个名为 orderInt 的函数,它传递了三个整数,如果三个整数是升序的,则返回 true,否则返回 false。到目前为止,这是我的代码:

def orderInt(a, b, c):
     print "Enter 3 integers: "
a = input()
b = input()
c = input()

如何比较变量?

【问题讨论】:

  • 请参阅stackoverflow.com/help/on-topic - 特别是一些问题仍然离题列表的第 3 项。
  • 您似乎希望我们为您编写一些代码。虽然许多用户愿意为陷入困境的程序员编写代码,但他们通常只会在发布者已经尝试自己解决问题时提供帮助。展示这项工作的一个好方法是包含您迄今为止编写的代码、示例输入(如果有的话)、预期输出和您实际获得的输出(输出、回溯等)。您提供的详细信息越多,您可能收到的答案就越多。检查FAQHow to Ask

标签: python python-2.7


【解决方案1】:

首先,你的缩进是错误的。

def orderInt():
    print "Enter 3 integers: "
    a = input()
    b = input()
    c = input()
    if a<b<c:
        return True
    else:
        return False

print orderInt()

其次,您的函数接受三个参数并接受输入。传递的参数将被您的inputs 覆盖。

def orderInt():
    print "Enter 3 integers: "
    if a<b<c:
        return True
    else:
        return False

a = input()
b = input()
c = input()

print orderInt(a,b,c)

希望这会有所帮助。

【讨论】:

  • 实际上print "Enter 3 integers: "应该在提示上方的函数之外
  • @GeorgeBou,我看到了,我给出了第二个解决方案。
猜你喜欢
  • 2016-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-01
  • 1970-01-01
  • 2015-05-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多