python中利用逻辑代码比较数字大小

mac2025-06-10  47

''' 比较输入的三个数字之间的大小,按从小到大排列 a,b,c 例如:输入2,5,3 输出:2,3,5 ''' def main(): a = int(input('please input value_a:')) b = int(input('please input value_b:')) c = int(input('please input value_c:')) if a > b and a > c: temp = c c = a a = temp if a > b: temp = a a = b b = temp elif b > a and b > c: temp = c c = b b = temp if a > b: temp = a a = b b = temp elif c > a and c > b: if a > b: temp = a a = b b = temp print('三个数按顺序从小到大排列为{},{},{}'.format(a,b,c)) if __name__ == '__main__': main()

最新回复(0)