<reponame>MouBieCat/MySchoolHomeWorkProject_Python
﻿'''
* Copyright (c) 2022 MouBieCat
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. 
'''

from typing import List

# 是否大於零
def not_zero(
    number:int, 
    showErrorMsg:bool=False
) -> bool:
    if number < 0 and showErrorMsg:
        print("該數字不是一個合法有效的數字")

    return number < 0

# 是否為質數
def is_prime_number(
    number:int
) -> bool:
    for nub in range(2, number):
        if number % nub == 0:
            return False
        
    return True

# 奇數 = True, 偶數 = False
def is_odd_number(
    number:int
) -> bool:
    return (number % 2 == 1)

# 獲取因數列表
def get_number_divisor_array(
    number:int, 
    showCountMsg:bool = False
) -> List[int]:

    # 使用該功能必須導入 
    # from typing import List
    # 函數庫語句

    # 聲明：該部分目前不再該課程當中，我只是想當作自己的經驗與練習用途！

    returnList = [] # 建立因數集合對象

    for nbs in range(1, number + 1):
        if number % nbs == 0:
            returnList.append(nbs)
            
    if showCountMsg:
        print("總共找到了 " + str(returnList.__len__()) + " 個因數")

    return returnList

# Main
number = int(input("請輸入一個正整數 => "))

if not not_zero(number, True):
    print(str(number) + " 它是一個質數"
          if is_prime_number(number)
          else str(number) + " 它不是一個質數")

    print(str(number) + " 它是一個奇數"
          if is_odd_number(number)
          else str(number) + " 它是一個偶數")

    for index in get_number_divisor_array(number):
        print(str(number) + " 的因數有 " + str(index))

﻿'''
* Copyright (c) 2022 MouBieCat
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. 
'''

from typing import List

# 是否大於零
def not_zero(
    number:int, 
    showErrorMsg:bool=False
) -> bool:
    if number < 0 and showErrorMsg:
        print("該數字不是一個合法有效的數字")

    return number < 0

# 是否為質數
def is_prime_number(
    number:int
) -> bool:
    for nub in range(2, number):
        if number % nub == 0:
            return False
        
    return True

# 奇數 = True, 偶數 = False
def is_odd_number(
    number:int
) -> bool:
    return (number % 2 == 1)

# 獲取因數列表
def get_number_divisor_array(
    number:int, 
    showCountMsg:bool = False
) -> List[int]:

    # 使用該功能必須導入 
    # from typing import List
    # 函數庫語句

    # 聲明：該部分目前不再該課程當中，我只是想當作自己的經驗與練習用途！

    returnList = [] # 建立因數集合對象

    for nbs in range(1, number + 1):
        if number % nbs == 0:
            returnList.append(nbs)
            
    if showCountMsg:
        print("總共找到了 " + str(returnList.__len__()) + " 個因數")

    return returnList

# Main
number = int(input("請輸入一個正整數 => "))

if not not_zero(number, True):
    print(str(number) + " 它是一個質數"
          if is_prime_number(number)
          else str(number) + " 它不是一個質數")

    print(str(number) + " 它是一個奇數"
          if is_odd_number(number)
          else str(number) + " 它是一個偶數")

    for index in get_number_divisor_array(number):
        print(str(number) + " 的因數有 " + str(index))
* Copyright (c) 2022 MouBieCat * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. # 是否大於零 # 是否為質數 # 奇數 = True, 偶數 = False # 獲取因數列表 # 使用該功能必須導入 # from typing import List # 函數庫語句 # 聲明：該部分目前不再該課程當中，我只是想當作自己的經驗與練習用途！ # 建立因數集合對象 # Main