Python编码练习

2024-10-03 15:24:17 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

如何比较变量?你知道吗


Tags: integers函数代码falsetrueinputdef整数
1条回答
网友
1楼 · 发布于 2024-10-03 15:24:17

首先,你的压痕是错误的。你知道吗

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

print orderInt()

第二,函数接受三个参数,同时也接受输入。传递的参数将被input覆盖

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)

希望这有帮助。你知道吗

相关问题 更多 >