''' 题目:0——100闭区间产生3个随机数,两种方法排序 法1:暴力遍历 法2:max(a,b,c)min(a,b,c) 注意:random,radint(0——100)产生随机数 '''
代码语言:javascript复制
import random
#生成随机数
#法1:暴力遍历
def fa1(a, b, c):
if(a > b):
temp = a
a = b
b = temp
if(a < c):
temp = a
a = c
c = temp
if(b < c):
temp = b
b = c
c = temp
print("法1从高到低{0}-{1}-{2}".format(a, b, c))
def fa2(a, b, c):
num_all = a b c
max1 = max(a, b, c)
min2 = min(a, b, c)
three = num_all - (max1 min2)
print("法2从低到高{0}-{1}-{2}".format(min2, three, max1))
def main():
a = random.randint(0, 100)
b = random.randint(0, 100)
c = random.randint(0, 100)
fa1(a,b,c)
fa2(a,b,c)
main()