正在看书自学中,贴出自己的作业,欢迎大家交流指正,一起进步~
# TempConvert
def TempConvert(value):
if tempstr[-1] in ['F','f']:
c = (eval(tempstr[0:-1]) - 32)/1.8
print ("The temperature is converted to {}C".format(int(c)))
elif tempstr[-1] in ['C','c']:
f = eval(tempstr[0:-1])*1.8 + 32
print("The temperature is converted to {}F".format(int(f)))
else:
print("Input wrong!")
tempstr = input("pls input the temperature with unit F or C: ")
while tempstr[-1] not in ['N','n']:
TempConvert(tempstr)
tempstr = input("pls input the temperature with unit F or C: ")
# Exchange rate conversion
while True:
try:
s=input('输入金额以¥或$结尾,输入E结束: ')
mode = s[-1]
if mode=='E':
break
elif mode=='$':
print(str(6*int(s[:-1]))+'¥')
else:
print(str(round(int(s[:-1])/6,2))+'$')
except:
print("Input Error!")
#draw a multicolored python
from turtle import *
setup(500, 400, 200, 200)
pencolor('green')
penup()
fd(-250)
pendown()
pensize(20)
seth(-40)
r = 0.1
g = 0.2
b = 0.3
for i in range(4):
pencolor((r+0.1*i, g+0.1*i, b+0.1*i))
circle(40, 80)
circle(-40, 80)
pencolor((r+0.1*4, g+0.1*4, b+0.1*4))
circle(40, 80/2)
fd(40)
pencolor((r+0.1*5, g+0.1*5, b+0.1*5))
circle(16, 180)
fd(40*2/3)
done()
# Equilateral Triangle
from turtle import *
setup(500, 400, 200, 200)
pencolor('green')
penup()
fd(-100)
seth(-90)
fd(50)
pendown()
pensize(5)
for theta in [0,120,-120]:
seth(theta)
fd(200)
done()
#叠加等边三角形的绘制
len = 40
#ang = 60
from turtle import *
setup()
seth(0)
fd(len)
seth(120)
fd(len)
seth(240)
fd(2*len)
seth(0)
fd(2*len)
seth(120)
fd(len)
seth(240)
fd(len)
seth(120)
fd(len)
done()
# Square without corners
from turtle import *
setup(500, 400, 200, 200)
pencolor('green')
penup()
fd(-100)
seth(-90)
fd(60)
for i in [0,90,180,270]:
fd(40)
seth(i)
fd(40)
pendown()
fd(120)
penup()
done()
#绘制六角形
from turtle import *
len = 180
for i in [0,1]:
seth(30+60*i)
fd(len)
seth(270+60*i)
fd(len)
seth(150+60*i)
fd(len)
penup()
seth(-30)
fd(len/3)
seth(-90)
fd(len/3)
pendown()
done()
# 绘制正方形螺旋线
from turtle import *
len = 500
setup()
penup()
seth(180)
fd(250)
seth(270)
fd(250)
pendown()
speed(10)
for i in range(1,15):
seth(90)
fd(len)
seth(0)
len = len - 9
fd(len)
seth(-90)
len = len - 9
fd(len)
seth(180)
len = len - 9
fd(len)
len = len - 9
done()