输入三个整数,按升序输出
a = int(input('请输入第一个整数:'))
b = int(input('请输入第二个整数:'))
c = int(input('请输入第三个整数:'))
if a > b > c:
print(c, b, a)
elif a > c > b:
print(b, c, a)
elif b > a > c:
print(c, a, b)
elif b > c > a:
print(a, c, b)
elif c > a > b:
print(b, a, c)
else:
print(a, b, c)
结果:
输入年份及 1-12月份,判断月份属于大月、小月、闰月、平月,并输出本月天数
year = int(input('请输入四位数年份:'))
month = int(input('请输入两位数月份:'))
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
f = 1
else:
f = 0
if month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12:
print(month, '是大月,共31天')
elif month == 4 or month == 6 or month == 9 or month == 11:
print(month, '月是小月,共30天')
elif month == 2 and f == 1:
print(month, '月是闰月,共29天')
elif month == 2 and f == 0:
print(month, '月是平月,共28天')
else:
print('月份数字错误,请输入1-12间月份数字!')
结果:
输入一个整数,显示其所有是素数因子
num = int(input('请输入一个整数:'))
for i in range(1, num + 1):
if num % i == 0:
for j in range(2, i):
if i % j == 0:
break
else:
print(i)
结果: