r = 25
S = 3.1415rr
print("{:.2f}".format(S))
name = input(“请输入你的名字:”)
print("{}同学,你好".format(name)) # name会放入{}里
print("{}同学,上课了".format(name))
def f(n):
if n ==1:
return 1
if n ==2:
return 1
return f(n-1)+f(n-2)
print(f(7))
a,b = 0,1
while a < 1000:
print(a,end=",") # 放在这里是避免输出 a+b>1000
a,b = b,a+b
a,b = 0,1
while b < 1000:
a,b = b,a+b
print(a, end=",")
import turtle
turtle.pensize(5) # 设置画笔为5像素
turtle.circle(20) # 绘制半径为20的圆
turtle.circle(60)
turtle.circle(100)
from datetime import datetime
t = datetime.now()
print(t)
print(t.year)
print(t.month)
print(t.day)
t.strftime("%x")
t.strftime("%X")
t1 = t.strftime("%Y-%m-%d %H:%M:%S")
str1 = input(“请输入人名:”)
str2 = input(“请输入国家名:”)
PinJie = (“世界这么大,{0}想去{1}看看”.format(str1,str2))
print(PinJie)
n = input(“请输入整数N:”)
sum = 0
for i in range(int(n)): # range函数
sum += i+1 # sum = sum+i+1
print(“结果:”,sum)
for h in range(1,10):
for l in range(1,h+1): # 每一次打是从1开始,到h结束
print(h*l,end=" ") # 99乘法表是 行x列
print()
def printline(h):
for l in range(1,h+1):
print(h*l,end=" “)
print(” ")
for h in range(1,10):
printline(h)
for h in range(1,10):
for l in range(1,h+1):
print("{0}{1}={2}".format(l,h,lh),end=" ")
sum = 0
shu = 1
for i in range(1,11):
shu = shu * i
sum = sum + shu
print(sum)
t = 1
for i in range(1,6):
t = (t+1)*2
print(t)
diet = “鸡蛋”,“牛肉”,“旺仔”,“快乐水”,“辣条”
for a in range(0,5):
for b in range(0,5): # 类似数字格式转化那道题,遍历diet
if not(a == b):
print("{}{}".format(diet[a],diet[b]))
from turtle import *
length = 5
angle = 144
def draw_path(path):
for i in path:
if i == “F”:
forward(100)
elif i == “+”:
right(angle)
path = “F+F+F+F+F”
speed()
draw_path(path)
exitonclick()
from turtle import *
fillcolor(“red”)
begin_fill()
while True: # 条件为真会一直执行下面的语句
forward(200)
right(144)
if abs(pos())<1: # 是否回到原点,1是像素,几乎是0
break
end_fill()
from turtle import *
fillcolor(“red”,“blue”)
begin_fill()
while True: # 条件为真会一直执行下面的语句
forward(200)
right(170)
if abs(pos())<1: # 是否回到原点,1是像素,几乎是0
break
end_fill()
import turtle
turtle.setup(650,350,200,200)
turtle.penup()
turtle.fd(-250)
turtle.pendown()
turtle.pensize(25)
turtle.pencolor(“red”)
turtle.seth(-40)
for i in range(4):
turtle.circle(40,80/2)
# 画弧线
turtle.circle(-40,80)
#绘制脖子
turtle.circle(40,80/2)
turtle.fd(40)
turtle.circle(16,180)
turtle.fd(40 * 2/3)
turtle.down()
import turtle
turtle.pensize(2)
turtle.pencolor(“purple”)
turtle.forward(50)
turtle.seth(-120)
turtle.forward(50)
turtle.seth(-60)
turtle.forward(-50)
import turtle
turtle.pensize(2)
turtle.pencolor(“purple”)
turtle.forward(50)
turtle.seth(-120)
turtle.forward(50)
turtle.seth(-60)
turtle.forward(-50)
turtle.penup()
turtle.seth(-60)
turtle.forward(25)
turtle.pendown()
turtle.seth(60)
turtle.forward(25)
turtle.seth(-60)
turtle.forward(25)
turtle.seth(-60) # 有点问题
turtle.forward(-25)
import turtle
turtle.pen(speed=0)
turtle.penup()
turtle.goto(-200,-200) # 以左下角某处为起点
turtle.pendown()
turtle.seth(0)
length = 400
while (length !=0):
turtle.forward(length)
turtle.left(90)
length -=2.5
turtle.hideturtle() # 隐藏海龟
turtle.done()