Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中比较两个没有循环或分支的数字_Python - Fatal编程技术网

在Python中比较两个没有循环或分支的数字

在Python中比较两个没有循环或分支的数字,python,Python,我必须比较两个数字,先写大一点,然后再写小一点,但我不知道如何得到小一点的数字。我目前有以下代码: a = int(input()) b = int(input()) c = round(((a + b) + abs(a - b)) / 2) x = "should be smaller one" print("{0}\n{1}".format(c, x)) 较小的是:c=round(((a+b)-abs(a-b))/2)如果我正确理解您的意思: In [1]: a , b = 3, 4 I

我必须比较两个数字,先写大一点,然后再写小一点,但我不知道如何得到小一点的数字。我目前有以下代码:

a = int(input())
b = int(input())
c = round(((a + b) + abs(a - b)) / 2)
x = "should be smaller one"
print("{0}\n{1}".format(c, x))

较小的是:
c=round(((a+b)-abs(a-b))/2)

如果我正确理解您的意思:

In [1]: a , b = 3, 4

In [2]: smaller = a if a < b else b

In [3]: smaller
Out[3]: 3
[1]中的
a,b=3,4
[2]中:如果a

您可以在这里替换
min(a,b)
对您不起作用吗?我们在学校刚开始使用python,所以我只限于基本操作较小的是:
c=round(((a+b)-abs(a-b))/2)
不能使用或类似的操作。什么样的课程禁止您使用逻辑?为了完整性起见,较大的课程显然是
d=a+b-c