115103108
python 基礎
1. Notebook LM
2.學習卡和測驗
3.寫一個程式附加說明
# 🎲 通用抽籤機
一個簡單、免費、開源的 Python 通用抽籤工具。
不限制使用情境,可以用於:
- 🎁 抽獎
- 👥 分組
- 🔢 決定順序
- 🎯 隨機選擇
- 🎮 遊戲
- 🎉 活動
- 🏫 課堂活動
- 💼 工作場合
- 👨👩👧👦 聚會
- 任何需要隨機抽籤的場合
---
## ✨ 功能
- 🎲 隨機抽籤
- 🔄 可以重新抽籤
- 📋 顯示完整抽籤順序
- 💾 匯出 CSV
- 🌏 支援中文
- 💻 支援 Windows / macOS / Linux
- 📦 不需要安裝第三方套件
- 🆓 免費使用
---
## 🖥️ 系統需求
需要:
- Python 3.8 或以上
支援:
- Windows
- macOS
- Linux
---
## 🚀 安裝
下載或 Clone 此專案:
```bash
git clone https://github.com/你的帳號/你的專案名稱.git
進入專案資料夾:
cd 你的專案名稱
▶️ 執行
使用:
python lottery.py
如果你的電腦使用 python3:
python3 lottery.py
📝 使用方式
程式啟動後,輸入想要抽籤的項目。
例如:
小明
小華
小美
小王
小陳
輸入完成後按 Enter。
程式會自動隨機排列:
==================================================
🎉 抽籤結果
==================================================
1. 小美
2. 小陳
3. 小明
4. 小王
5. 小華
==================================================
🔄 重新抽籤
抽籤完成後,可以選擇:
1. 重新抽籤
2. 儲存結果
3. 顯示目前結果
4. 結束程式
選擇 1 可以重新隨機抽籤。
💾 匯出結果
選擇:
2. 儲存結果
程式會建立:
抽籤結果.csv
CSV 可以使用以下軟體開啟:
Microsoft Excel
Apple Numbers
Google Sheets
LibreOffice Calc
📌 使用範例
抽籤
輸入:
Apple
Google
Microsoft
Amazon
NVIDIA
可能得到:
1. NVIDIA
2. Apple
3. Amazon
4. Microsoft
5. Google
每次重新抽籤都會產生新的隨機順序。
🛠️ 使用技術
本專案使用 Python 標準函式庫:
random
csv
不需要安裝任何第三方套件。
📁 專案結構
lottery/
│
├── lottery.py
├── README.md
└── 抽籤結果.csv
🔐 隨機方式
本程式使用 Python 的:
random.shuffle()
將輸入項目進行隨機排列。
📄 License
MIT License
你可以自由:
使用
修改
分享
Fork
用於個人或商業專案
import random
import csv
def input_items():
"""輸入抽籤項目"""
print("=" * 50)
print(" 🎲 通用抽籤機")
print("=" * 50)
print("\n請輸入要抽籤的項目")
print("例如:")
print("小明")
print("小華")
print("小美")
print("小王")
print("\n輸入完成後直接按 Enter:\n")
items = []
while True:
item = input()
if item.strip() == "":
break
items.append(item.strip())
return items
def draw(items):
"""進行隨機抽籤"""
if not items:
print("\n❌ 沒有任何抽籤項目!")
return None
result = items.copy()
random.shuffle(result)
return result
def show_result(result):
"""顯示抽籤結果"""
print("\n")
print("=" * 50)
print(" 🎉 抽籤結果")
print("=" * 50)
for index, item in enumerate(result, start=1):
print(f"{index:>3}. {item}")
print("=" * 50)
def save_csv(result):
"""儲存抽籤結果"""
filename = "抽籤結果.csv"
with open(filename, "w", newline="", encoding="utf-8-sig") as file:
writer = csv.writer(file)
writer.writerow(["順位", "項目"])
for index, item in enumerate(result, start=1):
writer.writerow([index, item])
print(f"\n✅ 抽籤結果已儲存為:{filename}")
def main():
items = input_items()
if not items:
print("❌ 沒有輸入任何項目,程式結束。")
return
result = draw(items)
show_result(result)
while True:
print("\n請選擇功能:")
print("1. 重新抽籤")
print("2. 儲存結果")
print("3. 顯示目前結果")
print("4. 結束程式")
choice = input("\n請輸入選項:")
if choice == "1":
result = draw(items)
show_result(result)
elif choice == "2":
save_csv(result)
elif choice == "3":
show_result(result)
elif choice == "4":
print("\n👋 感謝使用通用抽籤機!")
break
else:
print("\n❌ 無效選項,請輸入 1~4。")
if __name__ == "__main__":
main()









留言
張貼留言