python程序——(要搭配python(1)-(20)系列文章学习)


1 .第一个简单小程序:

print('a')
print('b')
print('c')

在这里插入图片描述
结果:
在这里插入图片描述

2 .第二个简单小程序:

#导入海龟绘图模块
import turtle
t=turtle.Pen()

#这是一个循环
for x in range(360):
    t.forward(x)
    t.left(59)#此数值不同画出的图形也不同

'''

这是一个与python有关的海龟绘图程序,为了体会python的缩进和注释方法

python的注释方法有两种:行注释 #
                        段注释 ''' '''

'''

在这里插入图片描述

3 .第三个简单小程序:

import turtle #导入turtle模块

turtle.showturtle() #显示箭头
turtle.write("绘制图形") #写下字符串
turtle.forward(300) #前进300像素
turtle.color('red') #画笔颜色变成红色
turtle.left(90) #箭头左转90度
turtle.forward(200) #前进200像素
turtle.goto(0,50)  #箭头跳到(0,50)坐标处
turtle.goto(0,0) 
turtle.penup() #抬起画笔,这样路径就不会被画出了
turtle.goto(0.300) 
turtle.pendown() #放下画笔,这样路径就可以被画出了
turtle.circle(100) #画半径100的圆

在这里插入图片描述

4 .第四个简单小程序:

import turtle
t=turtle.Pen()

#第一个圆
t.width(8)
t.color('blue')
t.penup()
t.goto(-180,40)
t.pendown()
t.circle(70)

#第二个圆
t.width(8)
t.color('black')
t.penup()
t.goto(-20,40)
t.pendown()
t.circle(70)

#第三个圆
t.width(8)
t.color('red')
t.penup()
t.goto(140,40)
t.pendown()
t.circle(70)

#第四个圆
t.width(8)
t.color('green')
t.penup()
t.goto(65,-40)
t.pendown()
t.circle(70)

#第五个圆
t.width(8)
t.color('orange')
t.penup()
t.goto(-100,-40)
t.pendown()
t.circle(70)

在这里插入图片描述

5 .第五个简单小程序:

import turtle
import math

#定义四个坐标点
x1,y1=100,100
x2,y2=100,-100
x3,y3=-100,-100
x4,y4=-100,100

#绘画出折线
t=turtle.Pen()
t.penup()
t.goto(x1,y1)
t.pendown()
t.write((x1,y1))

t.goto(x2,y2)
t.write((x2,y2))

t.goto(x3,y3)
t.write((x3,y3))

t.goto(x4,y4)
t.write((x4,y4))

#计算起始点到终点的距离
disc=math.sqrt((x1-x4)**2 + (y1-y4)**2)
t.penup()
t.goto(0,100)
t.pendown()
t.write(disc)

在这里插入图片描述

6 .第六个简单小程序:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值