python语言程序设计实例10_Python语言程序设计基础(2)—— Python程序实例解析...

标签:

温度转换

def tempConvert(ValueStr):

if ValueStr[-1] in ['F','f']:

ans = (eval(ValueStr[0:-1]) - 32)/1.8

print("{:.2f}C".format(ans))

elif ValueStr[-1]=='C' or ValueStr[-1]=='c':

ans = 1.8*eval(ValueStr[0:-1]) + 32

print("{:.2f}F".format(ans))

else:

print("格式错误")

str = input()

tempConvert(str)

画蟒蛇

import turtle

def drawSnake(radius,angle,length):

turtle.seth(-angle/2)

for i in range(length):

turtle.circle(radius,angle)

turtle.circle(-radius,angle)

turtle.circle(radius,angle/2)

turtle.fd(40)

turtle.circle(16,180)

turtle.fd(40*2/3)

turtle.setup(0.5,0.5)

turtle.penup()

turtle.fd(-250)

turtle.pendown()

turtle.pensize(25)

turtle.pencolor("purple")

drawSnake(40,120,4)

turtle.done()

习题部分

标签:

来源: https://www.cnblogs.com/TreeDream/p/9782282.html

你可能感兴趣的:(python语言程序设计实例10_Python语言程序设计基础(2)—— Python程序实例解析...)