python学习---第二周作业

 1 #!/usr/bin/env python3
 2 # -*- coding: utf-8 -*-
 3 
 4 #01 温度转换
 5 while True:
 6     val = input("请输入带温度表示符号的温度值(例如:32C): ")
 7     if val[-1] in ['C','c']:
 8         f = 1.8 * float(val[0:-1]) + 32
 9         print("转换后的温度为: %.2fF" % f)
10         break
11     elif val[-1] in ['F','f']:
12         c = (float(val[0:-1]) - 32) / 1.8
13         print("转换后的温度为: %.2fC" % c)
14         break
15     else:
16         print("输入有误")
17         continue
18 
19 #02 蟒蛇小程序
20 from turtle import *
21 import turtle
22 def drawSnake(rad, angle, len, neckrad):
23     for i in range(len):
24         turtle.circle(rad, angle)
25         turtle.circle(-rad, angle)
26     turtle.circle(rad, angle/2)
27     turtle.fd(rad)
28     turtle.circle(neckrad+1, 180)
29     turtle.fd(rad*2/3)
30 
31 def main():
32     turtle.setup(1360,768,0,0)
33     pythonsize = 10
34     turtle.pensize(pythonsize)
35     turtle.pencolor("#3B9909")
36     turtle.seth(-40)
37     drawSnake(40,80,5,pythonsize/2)
38     done()
39 
40 main()
41 
42 #03 使用turtle库中turtle.fd()函数和turtle.seth()函数绘制一个等边三角形
43 import turtle
44 
45 def main():
46     turtle.setup(1360,768,0,0)
47     pythonsize = 1
48     turtle.pensize(pythonsize)
49     turtle.pencolor("#3B9909")
50     turtle.seth(0)
51     turtle.fd(80)
52     turtle.seth(120)
53     turtle.fd(80)
54     turtle.seth(-120)
55     turtle.fd(80)
56     turtle.done()
57 
58 main()

 

posted @ 2017-10-27 11:26  hayden__wang  阅读(282)  评论(0编辑  收藏  举报