python生成100个随机数_Python_0——100闭区间产生3个随机数,两种方法排序
生活随笔
收集整理的這篇文章主要介紹了
python生成100个随机数_Python_0——100闭区间产生3个随机数,两种方法排序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
''' 題目:0——100閉區間產生3個隨機數,兩種方法排序 法1:暴力遍歷 法2:max(a,b,c)min(a,b,c) 注意:random,radint(0——100)產生隨機數 '''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()
總結
以上是生活随笔為你收集整理的python生成100个随机数_Python_0——100闭区间产生3个随机数,两种方法排序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jpa 不自动建表_如何来实现Sprin
- 下一篇: c++ websocket客户端_你要的