回覆列表
  • 1 # 一小學歷史課代表

    1本文需要載入的模組是:random

    2給出0到10之間的隨機整數:import randoma = random.randint(0,10)print(a)

    3給出9到10之間的隨機實數:import randoma = random.uniform(9,10)print(a)

    4從9、19、29、39、……、99之間,隨機選取一個實數:import randoma = random.randrange(9, 100, 10)print(a)

    5從列表[5,6,7,8,9]裡面,隨機選取一個數:import randoma = random.choice([5,6,7,8,9])print(a)

    6從一個字串裡面,隨機選取一個字元:import randoma = random.choice("從一個字串裡面,隨機選取一個字元!")print(a)

    7隨機打亂列表裡面的字元順序:import randoma = ["p","q","r","s","t","p","q","r","s","t","p","q","r","s","t",]random.shuffle(a)print(a)

    8從列表裡面隨機選取9個數字:import randoma = range(3,100,2)b = random.sample(a, 9)print(b)

  • 中秋節和大豐收的關聯?
  • 《情非得已》的原唱和歌詞它是哪一年出的?