Everybody in this country should learn how to program a computer,because it teaches you how to think.
——史蒂夫~乔布斯
圆的面积
import math radius = 25 area = math.pi*radius*radius print(area) print("{:.2f}".format(area))
输入
name = input("输入人名:") print("{}".format(name)) print("{}".format(name[0])) print("{}".format(name[1:]))
斐波那契
a , b = 1,1 while a < 1000 : print(a,end=',') a, b = b,a+b print("")
同心圆
import turtle turtle.pensize(2) turtle.circle(10) turtle.circle(20)
日期与时间
from datetime import datetime now = datetime.now() print(now) print(now.strftime("%x")) print(now.strftime("%X"))
习题部分
字符串拼接
str1 = input() str2 = input() print("{} {}".format(str1,str2))
sum(n)
n=input() sum=0 for i in range(int(n)+1): sum+=i print(sum)
9*9
for i in range(1,10): for j in range(1,i+1): print("{}*{}={:2}".format(j,i,j*i),end=' ') print("")
1! + 2! + 3! + ... + n!
n = input() sum = 0 tmp = 1 for i in range(1,int(n)+1): sum+=tmp tmp*=(i+1) print(sum)
猴子吃桃
ans = 1 for i in range(5): ans = (ans + 1)*2 print(ans)