Python tkinter繪圖對比EXCEL
def pv(r,n,m,f):#劉任昌函數參數r,n,m,f
p = m/r*(1 - 1/(1+r)**n)+f/(1+r)**n
return p#執行函數的結果傳回去
n=float(input('期數: '))#要計算轉為實數real nubers
m=float(input('收付: '))#浮點點float
f=float(input('終值: '))
for i in range(1,10):#迴圈
r = i*0.01
x=pv(r,n,m,f)
print('利率 ', r ,'價格 ', x)
import tkinter as tk#輸入tkinter繪圖
root = tk.Tk()
root.title('劉老猴python tkinter')
root.geometry('600x600')#寬度width改成600
canvas = tk.Canvas(root, width=600, height=600) # 加入 Canvas 畫布
canvas.pack()
x, y = 0, 0
canvas.create_line(0, 400, 500, 400, width=5,fill='purple')
canvas.create_line(5, 0, 5, 400, width=5,fill='purple')
for x in range(1, 400):
x1 = x+1
y1 = 400 - pv(x1,n,m,f)*400
canvas.create_line(x, y, x1, y1, width=5,fill='blue')
canvas.pack()
x = x1
y = y1
留言
張貼留言