python语言程序设计基础嵩天答案第二章_python语言程序设计基础(嵩天版),第二章程序练习题...
python語言程序設計基礎(嵩天版),第二章程序練習題
歡迎訪問江南燒酒的博客
2.2匯率兌換程序。按照1美元=6人民幣匯率編寫一個美元和人民幣的雙向兌換程序。
"""
2.2匯率兌換程序,美元和人民幣
"""
a = input("請輸入最后帶有¥或$符號的金額:")
if a[-1] in ['$','$']: #假如輸入金額的符號為$
r=6.7352*eval(a[0:-1])
print(' '+repr(r)+'人民幣')
elif a[-1] in ['¥','¥']: #假如輸入金額的符號為$
m=0.1485*eval(a[0:-1])
print(' '+repr(m)+'美元')
else:
print("輸入格式錯誤哦!")
2.3繪制彩色蟒蛇
#2.3繪制彩色蟒蛇
from turtle import *
setup(650,350,200,200)
penup()
fd(-250)
pendown()
pensize(25)
pencolor("purple")
seth(-40)
for i in range(4):
circle(40,80)
pencolor("yellow")
circle(-40,80)
pencolor("blue")
circle(40,80/2)
pencolor("red")
fd(40)
circle(16,180)
fd(40*2/3)
done()
2.4等邊三角形的繪制
#2.4等邊三角形的繪制
from turtle import *
setup(800,600,300,300)
penup()
pendown()
pensize(6)
pencolor("red")
seth(60) #第一條線
fd(120)
seth(-60)
fd(120)
seth(-180)
fd(120)
done()
2.5疊加等邊三角形的繪制
#2.5疊加等邊三角形
from turtle import *
setup(800,600,300,300)
penup()
pendown()
pensize(6)
pencolor("red")
seth(60) #第一條線
fd(120)
seth(-60)
fd(120)
seth(-180)
fd(120)
seth(-60)
fd(120)
seth(60)
fd(120)
seth(-60)
fd(120)
seth(-180)
fd(240)
seth(60)
fd(120)
done()
2.6無角正方形的繪制
#2.6無角正方形的繪制
from turtle import *
setup(500,500,300,300)
t = Pen()
for x in range(4):
t.pensize(9)
t.color("red")
t.up()
t.forward(25)
t.down()
t.forward(100)
t.up()
t.forward(25)
t.down()
t.left(90)
done()
2.7六角形的繪制
#2.7六角形的繪制
from turtle import *
setup(500,500,300,300)
penup()
pendown()
pensize(9)
pencolor("red")
seth(30)
fd(180)
seth(-90)
fd(180)
seth(-210)
fd(180)
seth(30)
fd(60)
seth(90)
fd(60)
seth(-30)
fd(180)
seth(210)
fd(180)
seth(90)
fd(180)
done()
2.8正方形螺旋線的繪制
#2.8正方形螺旋線的繪制
import turtle as t
t.setup(500,500,300,300)
t.pen(shown=True,pendown=False,speed=0)
a=500
t.goto(-250,-250)
t.seth(90)
t.pendown()
while(a!=0):
t.fd(a)
a-=2.5
t.right(90)
t.ht()
t.done()
總結
以上是生活随笔為你收集整理的python语言程序设计基础嵩天答案第二章_python语言程序设计基础(嵩天版),第二章程序练习题...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cad快捷键文件路径_办公格式转太难不会
- 下一篇: python定义类时括号_为什么在定义类