❶ python編寫函數,求三個數中的最小值
# 2021-05-11 Luke
num1 = input("請輸入第一個數:")
num2 = input("請輸入第二個數:")
num3 = input("請輸入第三個數:")
num = [num1, num2, num3]
num.sort()
print(num[0])
❷ python輸入一個正整數,求該數所有的因數
# 2021-05-17 Luke
while True:
num = input("請輸入一個正整數:")
i = 1
num_count = []
while i <= int(num):
if int(num) % i == 0:
num_count.append(i)
i += 1
print(num + "的公因數有:")
print(*num_count)
❸ 用python編寫程序,輸入一個正整數n,求0到這個數以內的所有基數和與偶數和
# 2021-05-12 Luke
while True:
number = int(input("請輸入一個正整數:"))
num = number + 1
o = 0
j = 0
for a in range(0, num):
if a % 2 == 0:
o = o + a
else:
j = j + a
print("0~" + str(number) + "偶數的和是:" + str(o))
print("0~" + str(number) + "奇數的和是:" + str(j))