├── .gitignore ├── 2024.10.24 ├── 413401120_HA0.py ├── 413401120_HA1.py ├── 413401120_HA2.py └── 413401120_HA3.py ├── 2025.02.27 └── 413401120_H1.py ├── 2025.03.13 └── 413401120_H1.py ├── 2025.03.27 ├── 413401120_Q1.py └── 413401120_Q2.py ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | .idea/ 161 | -------------------------------------------------------------------------------- /2024.10.24/413401120_HA0.py: -------------------------------------------------------------------------------- 1 | # WatchAndyTW, 2024/10/25 2 | 3 | def main(): 4 | # Get user input IC 5 | # 取得使用者輸入之全年綜合所得 6 | ic = int(input("請輸入全年綜合所得(元):")) 7 | # Calculate NIC 8 | # 計算全年綜合所得淨額 9 | nic = ic - 300000 10 | # Check for NIC 11 | # 檢測全年綜合所得淨額 12 | if nic > 0: 13 | # Make the number smaller for better coding experience 14 | # 把數字簡化以利編寫 15 | nic_small = nic / 10000 16 | # Default to 5% 17 | # 預設乘數為 5% 18 | multiplier = 0.05 19 | if 54 < nic_small <= 121: 20 | multiplier = 0.12 21 | elif 121 < nic_small <= 242: 22 | multiplier = 0.20 23 | elif 242 < nic_small <= 453: 24 | multiplier = 0.30 25 | elif nic_small > 453: 26 | multiplier = 0.40 27 | # Calculate tax 28 | # 計算所得稅 29 | tax = nic * multiplier 30 | # Print result 31 | # 顯示結果 32 | print("今年的所得稅為:{}".format(tax)) 33 | else: 34 | # Print result 35 | # 顯示結果 36 | print("今年的所得稅為:0") 37 | print("月平均可支用所得為:{}".format(ic / 12)) 38 | 39 | main() 40 | 41 | # 本檔案僅為公開交流使用 42 | # This file is public for communication only 43 | # https://github.com/WatchAndyTW/PythonHomework/blob/main/2024.10.24/413401120_HA0.py -------------------------------------------------------------------------------- /2024.10.24/413401120_HA1.py: -------------------------------------------------------------------------------- 1 | # WatchAndyTW, 2024/10/25 2 | 3 | import math 4 | 5 | def main(): 6 | # Get user inputs 7 | # 取得使用者輸入 8 | a = int(input("請輸入 a 參數:")) 9 | b = int(input("請輸入 b 參數:")) 10 | c = int(input("請輸入 c 參數:")) 11 | # Calculation 12 | # 數學計算 13 | d = (b ** 2) - (4 * a * c) 14 | if d > 0: 15 | print("x 為實根:") 16 | x1 = int((-b - math.sqrt(d)) / (2 * a)) 17 | x2 = int((-b + math.sqrt(d)) / (2 * a)) 18 | print("x = {}, {}".format(x1, x2)) 19 | elif d == 0: 20 | print("x 為重根:") 21 | x = int(-b / (2 * a)) 22 | print("x = {}".format(x)) 23 | else: 24 | print("x 沒有實根") 25 | return 26 | 27 | main() 28 | 29 | # 本檔案僅為公開交流使用 30 | # This file is public for communication only 31 | # https://github.com/WatchAndyTW/PythonHomework/blob/main/2024.10.24/413401120_HA1.py -------------------------------------------------------------------------------- /2024.10.24/413401120_HA2.py: -------------------------------------------------------------------------------- 1 | # WatchAndyTW, 2024/10/25 2 | 3 | import random 4 | 5 | def main(): 6 | # Roll dice for player 7 | # 玩家擲骰子 8 | player_dices = roll_dice() 9 | player_score = calc_score(player_dices) 10 | print("Player: {}, Score: {}".format(' '.join(str(x) for x in player_dices), player_score)) 11 | # Roll dice for computer 12 | # 電腦擲骰子 13 | computer_dices = roll_dice() 14 | computer_score = calc_score(computer_dices) 15 | print("Computer: {}, Score: {}".format(' '.join(str(x) for x in computer_dices), computer_score)) 16 | # Calculate result 17 | # 計算結果 18 | if player_score > computer_score: 19 | print("Player wins!") 20 | elif computer_score > player_score: 21 | print("Computer wins!") 22 | else: 23 | print("Draw!") 24 | 25 | # Roll dice function 26 | # 擲骰子函數 27 | def roll_dice(): 28 | dices = [] 29 | for i in range(1,6): 30 | dices.append(random.randint(1, 6)) 31 | return dices 32 | 33 | # Calculate score function 34 | # 計算分數函數 35 | def calc_score(dices): 36 | score = 0 37 | for i in range(len(dices)): 38 | if int(dices[i]) == 3: 39 | continue 40 | score += int(dices[i]) 41 | return score 42 | 43 | main() 44 | 45 | # 本檔案僅為公開交流使用 46 | # This file is public for communication only 47 | # https://github.com/WatchAndyTW/PythonHomework/blob/main/2024.10.24/413401120_HA2.py -------------------------------------------------------------------------------- /2024.10.24/413401120_HA3.py: -------------------------------------------------------------------------------- 1 | # WatchAndyTW, 2024/10/25 2 | 3 | import random 4 | 5 | def main(): 6 | # Define variables 7 | # 宣告變數 8 | cardinality = 0 9 | even = 0 10 | rolled = [] 11 | red_gk_money = 0 12 | stop_red_gk = False 13 | black_gk_money = 0 14 | stop_black_gk = False 15 | multiplier = 0 16 | while True: 17 | # Increase multiplier 18 | # 增加乘數 19 | multiplier += 1 20 | # Roll dice 21 | # 擲骰子 22 | dice = roll_dice() 23 | # Increase counter if the number wasn't rolled before 24 | # 如果之前沒有骰到過這個數字,增加計數器 25 | if dice not in rolled: 26 | if dice % 2 == 0: 27 | even += 1 28 | else: 29 | cardinality += 1 30 | # Append number to list 31 | # 將數字加入列表中 32 | rolled.append(dice) 33 | # Check if GK met 34 | # 檢查 GK 是否達到 35 | if cardinality == 3 and not stop_black_gk: 36 | stop_black_gk = True 37 | black_gk_money = multiplier * 100 38 | if even == 3 and not stop_red_gk: 39 | stop_red_gk = True 40 | red_gk_money = multiplier * 100 41 | # Stop the loop if met the condition 42 | # 如果達到條件則停止循環 43 | if cardinality == 3 and even == 3: 44 | break 45 | # Print result 46 | # 顯示結果 47 | print(' '.join(str(x) for x in rolled)) 48 | print("總花費:{}".format(multiplier * 100)) 49 | for i in range(1, 7): 50 | x = 0 51 | for j in rolled: 52 | if i == j: 53 | x += 1 54 | print("+{} 點小賞:{} 個".format(i, x)) 55 | print("得到紅 GK 時的花費:{}".format(red_gk_money)) 56 | print("得到黑 GK 時的花費:{}".format(black_gk_money)) 57 | 58 | # Roll dice function 59 | # 擲骰子函數 60 | def roll_dice(): 61 | return random.randint(1, 6) 62 | 63 | main() 64 | 65 | # 本檔案僅為公開交流使用 66 | # This file is public for communication only 67 | # https://github.com/WatchAndyTW/PythonHomework/blob/main/2024.10.24/413401120_HA3.py -------------------------------------------------------------------------------- /2025.02.27/413401120_H1.py: -------------------------------------------------------------------------------- 1 | # WatchAndyTW, 2025/02/27 2 | 3 | def factor_number_generator(): 4 | num = int(input("Enter a number: ")) 5 | print([x for x in range(1, num) if num % x == 0]) 6 | 7 | factor_number_generator() 8 | -------------------------------------------------------------------------------- /2025.03.13/413401120_H1.py: -------------------------------------------------------------------------------- 1 | import random 2 | import re 3 | 4 | pattern = re.compile("^[a-z]+$") 5 | answer_list = ["apple", "banana", "kiwi"] 6 | show_char_list = [] 7 | 8 | def main(): 9 | answer = random.choice(answer_list) 10 | print(f'題目:{"".join("-" for _ in range(len(answer)))}') 11 | win = False 12 | for i in range(5): 13 | print(f"========== Round {i + 1} ==========") 14 | char = ask_for_char() 15 | show_char_list.append(char) 16 | print_text = "".join(x if x in show_char_list else "-" for x in answer) 17 | if print_text == answer: 18 | win = True 19 | break 20 | print(f'當前狀態:{"".join(x if x in show_char_list else "-" for x in answer)}') 21 | print(f"=============================") 22 | print("".join(f"你猜對了!答案是:{answer}!" if win else f"遊戲失敗!正確答案是:{answer}!")) 23 | 24 | def ask_for_char(): 25 | char = input("請輸入一個英文字母:") 26 | if len(char) > 1: 27 | print("輸入錯誤,請重新輸入一個英文字母。") 28 | char = ask_for_char() 29 | elif not pattern.match(char): 30 | print("輸入錯誤,請重新輸入一個英文字母。") 31 | char = ask_for_char() 32 | elif char in answer_list: 33 | print("輸入錯誤,請重新輸入一個英文字母。") 34 | char = ask_for_char() 35 | return char 36 | 37 | main() -------------------------------------------------------------------------------- /2025.03.27/413401120_Q1.py: -------------------------------------------------------------------------------- 1 | # WatchAndyTW, 2025/03/27 2 | 3 | print("".join([x.upper() if x.islower() else chr(((ord(x) - ord('A') + 3) % 26) + ord('A')) for x in reversed(str(input("請輸入測資:")))])) -------------------------------------------------------------------------------- /2025.03.27/413401120_Q2.py: -------------------------------------------------------------------------------- 1 | # WatchAndyTW, 2025/03/27 2 | 3 | def main(text: str): 4 | text = list(map(int, text.split(" "))) 5 | mid = len(text) // 2 6 | front = sum(text[:mid]) 7 | back = sum(text[mid:]) 8 | print("天秤傾左") if front > back else print("天秤保持水平") if front == back else print("天秤傾右") 9 | 10 | main(str(input("請輸入測資:"))) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 WatchAndyTW 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 大一程式設計概論作業 2 | - 本倉庫僅為公開交流使用 3 | - 建議大家還是先自己寫,如果不會的話再過來看 4 | - 本人並不推崇抄代碼 😂😂 5 | - 此倉庫將會持續更新 --------------------------------------------------------------------------------