简体   繁体   English

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

[英]Comparing two numbers without loops or branching in Python

I have to compare two numbers and write greater, then smaller, but I don't know how to get smaller one. 我必须比较两个数字并写入更大,然后更小,但我不知道如何变小。 I currently have this code: 我目前有这个代码:

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)

If I right understand you: 如果我理解你:

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

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

In [3]: smaller
Out[3]: 3

Here you can replace < to other operator 在这里你可以替换<到其他运营商

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM