Python 第一周


先来看看第一个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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值