Professional Documents
Culture Documents
程式設計 期中
程式設計 期中
km= float(input("km:"))
m= km*1000-1500
z= int(input("late fare enter 0,general fare enter 1:"))
if z>0:
price= 95+5*math.ceil(m/500)
if price>800:
discount= round(price*0.95)
print("general Price:",discount)
else:
print("general Price:",price)
else:
price= 118+8*math.ceil(m/500)
if price>950:
discount= round(price*0.97)
print("night Price:",discount)
else:
print("night Price:",price)
import math
r =eval(input("正五邊形中心到頂點的距離:"))
s =2*r*math.sin(math.pi/5) #正五邊形的邊長
z =s/(2*math.tan(math.pi/5)) #內切圓半徑
Area1 =0.25*(5*(5+2*5**0.5))**0.5*s**2 #五邊形面積
Area2 =z**2*math.pi #內切圓面積
Area3 =Area1-Area2
print("五邊形面積:",format(Area1,".3f")) #取到小數點後第三位
print("內切圓面積差:",format(Area3,".3f"))
z= int(input("輸入執行次數:"))
a ="第一個矩形在第二個矩形內:"
b ="第二個矩形在第一個矩形內:"
c ="兩個矩形交疊:"
d ="兩個矩形不交疊分離:"
for i in range(z):
x1,y1,h1,w1 =eval(input("輸入第一個矩形中心座標和高、寬"))
x2,y2,h2,w2 =eval(input("輸入第二個矩形中心座標和高、寬"))
if x1-0.5*w1>= x2-0.5*w2 and x1+0.5*w1 <= x2+0.5*w2 and y1-0.5*h1 >= y2-
0.5*h2 and y1+0.5*h1 <= y2+0.5*h2:
print(f"{a:^10}")
elif x1-0.5*w1<= x2-0.5*w2 and x1+0.5*w1 >= x2+0.5*w2 and y1-0.5*h1 <= y2-
0.5*h2 and y1+0.5*h1 >= y2+0.5*h2:
print(f"{b:^10}")
elif x1-0.5*w1<= x2-0.5*w2 or x1+0.5*w1 >= x2+0.5*w2 or y1-0.5*h1 <= y2-
0.5*h2 or y1+0.5*h1 >= y2+0.5*h2:
print(f"{c:^10}")
else:
print(f"{d:^10}")