1.生成日历
import calendar
yy = int(input("输入年份: "))
mm = int(input("输入月份: "))
print(calendar.month(yy,mm))
输出结果如下:
输入年份: 2015
输入月份: 6
June 2015
Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
2.生成斐波那契数列
def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
nterms = int(input("您要输出几项? "))
if nterms <= 0:
print(“输入正数”)
else:
print(“斐波那契数列:”)
for i in range(nterms):
print(recur_fibo(i))