先来看看第一个Python程序
>>>print("hello,world")
hello,world
使用print()函数把希望打印的文字用单引号或者双引号括起来。
下面是这周学习到的Python内容:
数据类型
整型int
浮点float
字符串str
……
可以通过type()函数查看变量和数据的类型。
turtle库的使用方法
turtle.setup(width, height,startx, starty)
根据setup()函数设置窗体大小及位置。
turtle.goto(x,y)
绝对坐标。
实例一:温度转换
Tem = input("请输入带有符号的温度值:")
if Tem[-1] in {"C","c"}:
c = eval(Tem[0:-1])
f = 1.8*c+32
print("转换后的温度为:%.2fF"%f)
elif Tem[-1] in {"F","f"}:
f = eval(Tem[0:-1])
c = (f-32)/1.8
print("转换后的温度为:%.2fC"%c)
else:
print("输入有误")
实例二:绘制等边三角形
import turtle
turtle.fd(100)
turtle.seth(120)
turtle.fd(100)
turtle.seth(240)
turtle.fd(100)
turtle.done()
实例三:绘制如图所示同心圆
import turtle
turtle.pencolor("red")
turtle.penup()
turtle.goto(0,-30)
turtle.pendown()
turtle.circle(30)
turtle.pencolor("orange")
turtle.penup()
turtle.goto(0,-50)
turtle.pendown()
turtle.circle(50)
turtle.pencolor("yellow")
turtle.penup()
turtle.goto(0,-70)
turtle.pendown()
turtle.circle(70)
turtle.pencolor("green")
turtle.penup()
turtle.goto(0,-90)
turtle.pendown()
turtle.circle(90)
turtle.pencolor(0,1,1)
turtle.penup()
turtle.goto(0,-110)
turtle.pendown()
turtle.circle(110)
turtle.pencolor("blue")
turtle.penup()
turtle.goto(0,-130)
turtle.pendown()
turtle.circle(130)
turtle.pencolor("purple")
turtle.penup()
turtle.goto(0,-150)
turtle.pendown()
turtle.circle(150)
turtle.pencolor(1,0.84,0)
turtle.penup()
turtle.goto(0,-170)
turtle.pendown()
turtle.circle(170)
turtle.pencolor(0.93,0.50,0.93)
turtle.penup()
turtle.goto(0,-190)
turtle.pendown()
turtle.circle(190)
turtle.done()