python程序设计与算法基础教程(第2版)微课版 13章上机实践3、6、7、8、9、10、11题

在这里插入图片描述

在这里插入图片描述

#3、程序代码
from tkinter import *
root=Tk()
c=Canvas(root,bg=‘white’,width=280,height=70);c.pack()
c.create_oval(10,10,60,60,fill=‘blue’)
c.create_oval(70,10,120,60,fill=‘blue’)
c.create_oval(130,25,180,45,dash=(5,))
c.create_oval(190,10,270,50,dash=(5,),width=2)
#3、程序结果
在这里插入图片描述

#6、程序代码
from tkinter import *
root=Tk()
c=Canvas(root,bg=‘white’,width=250,height=70);c.pack()
c.create_polygon(35,10,10,60,60,60,fill=‘red’,outline=‘black’)
c.create_polygon(70,10,120,10,120,60,fill=‘red’,outline=‘black’)
c.create_polygon(130,10,180,10,180,60,130,60)
c.create_polygon(190,10,240,10,190,60,240,60,fill=‘white’,outline=‘black’)
#6、程序结果
在这里插入图片描述

#7、程序代码
from tkinter import *
import math
WIDTH=510;HEIGHT=210
ORIGIN_X=2;ORIGIN_Y=HEIGHT/2
SCALE_X=40;SCALE_Y=100
ENDARC=3602
ox=0;oy=0;x=0;y=0
arc=0
root=Tk()
c=Canvas(root,bg=‘white’,width=WIDTH,height=HEIGHT);c.pack()
c.create_text(200,20,text=‘y=sin(x)’)
c.create_line(0,ORIGIN_Y,WIDTH,ORIGIN_Y)
c.create_line(ORIGIN_X,0,ORIGIN_X,HEIGHT)
for i in range(0,ENDARC+1,10):
arc=math.pi
i*2/360
x= ORIGIN_X + arc * SCALE_X
y=ORIGIN_Y-math.sin(arc)*SCALE_Y
c.create_line(ox,oy,x,y)
ox=x;oy=y
#7、程序结果
在这里插入图片描述

#8、程序代码
import turtle
p = turtle.Turtle()
p.color(“red”)
p.pensize(3)
turtle.speed(1)
p.goto(0,0)
for i in range(3):
p.left(120)
p.forward(100)

p.up()
p.goto(100,0)
p.down()
p.color(“green”)
p.pensize(3)
turtle.speed(1)
p.goto(100,0)
for i in range(4):
p.forward(100)
p.left(90)

p.up()
p.goto(300,0)
p.down()
p.color(“blue”)
p.pensize(3)
turtle.speed(1)
p.goto(300,0)
for i in range(5):
p.forward(100)
p.left(72)

p.up()
p.goto(-400,0)
p.down()
p.write(“绘制完成!”,font=(“Arial”,20))
#8、程序结果
在这里插入图片描述

#9、程序代码
import matplotlib.pyplot as plt
plt.plot([5,11,17,23,29])
plt.ylabel(‘y=6x+5’)
plt.show()
#9、程序结果

在这里插入图片描述

#10程序代码
import matplotlib.pyplot as plt
import math
x=[2math.pii/100 for i in range(200)]
y=[math.cos(i) for i in x]
plt.plot(x,y)
plt.show()
#10、程序结果
在这里插入图片描述

11、程序代码
import numpy as np
import matplotlib.pyplot as plt
def f(t):
return np.exp(-t)np.sin(2np.pit)
t1=np.arange(0.0,5.0,0.1)
t2=np.arange(0.0,5.0,0.02)
plt.figure(1)
plt.subplot(211)
plt.plot(t1,f(t1),‘bo’,t2,f(t2),‘k’)
plt.subplot(212)
plt.plot(t2,np.sin(2
np.pi*t2),‘r–’)
plt.show()
#11、程序结果
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值