实验目的及要求:
一、实验目的:
(1)掌握解决计算问题的一般方法。
(2)掌握Python语言的基本语法,包括缩进、变量、命名等。
(3)掌握Python语言绘图的一般方法。
(4)了解Python标准库的导入和使用。
二、实验要求:
(1)完成课后习题2.1~2.5。
(2)使用Pycharm+Python或Pycharm+Anaconda或Visual Studio Code完成程序编写、调试、运行,并将代码及运行结果截图整理成文档,形成实验报告,并总结心得体会。
实验内容:
2.1:
print("刘慧欣在小说《三体》中写道:“不要轻视简单,简单意味着坚固,整个数学大厦,都是建立在这种简单到不能再简单,但在逻辑上坚如磐石的公理的基础上。”")
运行结果:
2.2:
from prettytable import PrettyTable
t=PrettyTable(["序号","课程","成绩","学分"])
t.add_row([1,"程序设计基础",98,2])
t.add_row([2,"大学物理(1)",89,3])
t.add_row([3,"高等数学(1)",75,3])
t.add_row([4,"大学英语(1)",100,3])
print(t)
2.3:
import time
print("\033[33;44m",end="")
print("\r| * |",end="")
time.sleep(0.3)
print("\r| * |",end="")
time.sleep(0.3)
print("\r| * |",end="")
time.sleep(0.3)
print("\r| * |",end="")
print("\033[0m")
运行结果:
2.4:
from turtle import color
color=input("Enter a color:")
noun=input("Enter a uncountable noun:")
print("Roses are",color,end=",")
print(noun,"is blue",end=",")
print("my love is you")
运行结果:
2.5:
from re import X
import turtle
coordinate_x=[-110,0,110,-55,55]
coordinate_y=[-25,-25,-25,-75,-75]
color_of_circle=["red","blue","green","yellow","black"]
turtle.pensize(5)
turtle.color("red")
turtle.penup()
turtle.goto(-110,-25)
turtle.pendown()
turtle.circle(40,360)
turtle.color("blue")
turtle.penup()
turtle.goto(0,-25)
turtle.pendown()
turtle.circle(40,360)
turtle.color("green")
turtle.penup()
turtle.goto(110,-25)
turtle.pendown()
turtle.circle(40,360)
turtle.color("yellow")
turtle.penup()
turtle.goto(-55,-75)
turtle.pendown()
turtle.circle(40,360)
turtle.color("black")
turtle.penup()
turtle.goto(55,-75)
turtle.pendown()
turtle.circle(40,360)
turtle.hideturtle()
turtle.done()
运行结果: