当前位置:网站首页>PyQt5 rapid development and actual combat 10.2 compound interest calculation && 10.3 refresh blog clicks
PyQt5 rapid development and actual combat 10.2 compound interest calculation && 10.3 refresh blog clicks
2022-07-31 12:31:00 【Ding Jiaxiong】
PyQt5快速开发与实战
文章目录
10. 第10章 PyQt5 实战一:Classic program development
10.2 复利计算 && 10.3 Refresh blog hits
10.2.1 Compound interest calculation business
复利计算,It means after each interest accrual period,The interest accrued in the current period must be added to the principal,以计算下期的利息.这样,in each interest period,The interest of the previous period will become the interest-earning principal,即以利生利,也就是俗称的“利滚利”.This involves the present value of compound interest、Compound interest future value and compound interest calculation formula.
复利现值,It means in the case of calculating compound interest,To reach a certain amount of money in the future,The principal that must be invested now.所谓复利,Also known as lee-on-galley,It refers to the return of a deposit or investment,A way to make a new round of investment with capital and profit.
复利终值,It refers to the interest earned on the principal within the agreed period,Add the interest to the principal and then calculate the interest,The sum of the principal that is rolled over to the end of the agreed period.
复利计算公式:
其中P为本金,i为利率,nfor the holding period.
举例:
例如:某人用20000RMB yuan to invest in a project,annual rate of return5%,So what is the interest income after two years?
Calculated according to the compound interest formula,The interest income earned is:
20000X(1+5%)^2-2000×(1+5%)×(1+5%)
= 2000 ×1.05 ×1.05= 22050 (元)
10.2.2 Interface and logic implementation
# -*- coding: utf-8 -*-
''' 【简介】 银行复利计算 '''
from __future__ import division
import sys
from PyQt5.QtWidgets import (QApplication, QComboBox, QDialog,
QDoubleSpinBox, QGridLayout, QLabel)
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
principalLabel = QLabel("Principal:")
self.principalSpinBox = QDoubleSpinBox()
self.principalSpinBox.setRange(1, 1000000000)
self.principalSpinBox.setValue(1000)
self.principalSpinBox.setPrefix("RMB ")
rateLabel = QLabel("Rate:")
self.rateSpinBox = QDoubleSpinBox()
self.rateSpinBox.setRange(1, 100)
self.rateSpinBox.setValue(5)
self.rateSpinBox.setSuffix(" %")
yearsLabel = QLabel("Years:")
self.yearsComboBox = QComboBox()
self.yearsComboBox.addItem("1 year")
self.yearsComboBox.addItems(["{0} years".format(x)
for x in range(2, 31)])
amountLabel = QLabel("Amount")
self.amountLabel = QLabel()
grid = QGridLayout()
grid.addWidget(principalLabel, 0, 0)
grid.addWidget(self.principalSpinBox, 0, 1)
grid.addWidget(rateLabel, 1, 0)
grid.addWidget(self.rateSpinBox, 1, 1)
grid.addWidget(yearsLabel, 2, 0)
grid.addWidget(self.yearsComboBox, 2, 1)
grid.addWidget(amountLabel, 3, 0)
grid.addWidget(self.amountLabel, 3, 1)
self.setLayout(grid)
self.principalSpinBox.valueChanged.connect(self.updateUi)
self.rateSpinBox.valueChanged.connect(self.updateUi)
self.yearsComboBox.currentIndexChanged.connect(self.updateUi)
self.setWindowTitle("Interest")
self.updateUi()
def updateUi(self):
principal = self.principalSpinBox.value()
rate = self.rateSpinBox.value()
years = self.yearsComboBox.currentIndex() + 1
amount = principal * ((1 + (rate / 100.0)) ** years)
self.amountLabel.setText("RMB {0:.2f}".format(amount))
if __name__=="__main__":
from pyqt5_plugins.examples.exampleqmlitem import QtCore
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
app = QApplication(sys.argv)
form = Form()
form.show()
sys.exit(app.exec_())
10.3 Refresh blog hits
import sys
import time
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class WebView(QWebEngineView):
def __init__(self ):
super(WebView, self).__init__()
url = 'https://blog.csdn.net/weixin_44226181?type=blog'
self.load( QUrl( url ) )
self.show()
QTimer.singleShot(1000*3 , self.close)
if __name__ == '__main__':
app = QApplication(sys.argv)
web = WebView()
print('### exec succeed !')
sys.exit(app.exec_())
call the main window
if __name__ == '__main__' :
for i in range(5):
os.system("python openweb.py")
print("Refreshing page. 次数 =>" , i)
time.sleep(5)
边栏推荐
- JVS低代码能力简介及功能清单
- JVS函数公式使用场景介绍
- [Shader] Shader official example [easy to understand]
- Standard SQL/JSON - the sobering part
- Different lower_case_table_names settings for server (‘1‘) and data dictionary (‘0‘) 解决方案
- Indoor real-time laser SLAM control method based on biological excitation neural network
- Exploring Plain Vision Transformer Backbones for Object Detection Paper Reading Notes
- Caused by: 类找不到: org.apache.flink.table.planner.delegation.ParserFactory或者ExecutorFactory
- JVS开发套件产品定位
- 使用docker搭建mysql主从
猜你喜欢
随机推荐
Service discovery of kubernetes
使用openssl命令生成证书和对应的私钥,私钥签名,公钥验签
建情人节表白网站(超详细过程,包教包会)
三相PWM整流器预测直接功率控制
busybox之reboot命令流程分析
Comparison of ipv4 and ipv6 (IPV4)
Character Functions and String Functions
AMBA APB学习记录(AMBA 2.0)
Encapsulation of conversion between Json and objects (Gson)
LRU缓存[线性表 -> 链表 -> hash定位 -> 双向链表]
ASM外部冗余是否可以替换磁盘
Build a Valentine's Day confession website (super detailed process, package teaching package)
线性表的基本概念
纷享销客罗旭对话元气森林黄晓枫:零售数字化的终点不是创新,而是数据
关于==和equals的区别和联系,面试这么回答就可以
LeetCode - 025. 链表中的两数相加
TOGAF10标准读书会第2场活动精彩继续,高光时刻回顾!
MySQL模糊查询性能优化
连续变量离散化教程
Basic use of dosbox [easy to understand]