#Beginner - Python Random and Lists

Random number - Wikipedia

Python random Module - Generate Random Numbers/Sequences - AskPython

模組(Module)就是一個檔案,包含了相關性較高的程式碼。隨著應用程式的開發規模越來越大,我們不可能把所有的程式碼都寫在同一份Python檔案中,一定會將關聯性較高的程式碼抽出來放在不同的檔案中來形成模組(Module),主程式再透過引用的方式來使用。所以模組(Module)可以提高程式碼的重用性(Reusable)且易於維護。

解析Python模組(Module)和套件(Package)的概念

<aside> 💡 random.random() → return the next random floating point number between 0.0 to 1.0 (not included 1)

</aside>

  1. day4-1-module.py

import my_module
print(my_module.pi)
my_module.py
pi=3.14159
  1. day4-1-random-number.py
import random
random_integer = random.randint(1,10)
print(random_integer)

#Generate a floating random number between 0 to 1
random_float = random.random()
print(random_float)

#How to generate 0 to 5? random_float times 5 (0 to 4.99999)
random_float = random.random() * 5
print(random_float)