❶ 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))