当前位置:网站首页>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)
边栏推荐
猜你喜欢
普林斯顿微积分读本03第二章--编程实现函数图像绘制、三角学回顾
DCM 中间件家族迎来新成员
alert(1) (haozi.me)靶场练习
Exploring Plain Vision Transformer Backbones for Object Detection 论文阅读笔记
MySQL面试八股文(2022最新整理)
Shengxin Weekly Issue 38
Exploring Plain Vision Transformer Backbones for Object Detection Paper Reading Notes
JVS设置不同应用的登录时效时间
kernel syscore
2022年最新重庆建筑安全员模拟题库及答案
随机推荐
Selenium自动化测试之Selenium IDE
PAT exam summary (exam experience)
关于Mysql数据库的介绍
Markdown编辑器语法
How to correctly write the binary stream of the file returned by the server to the local file and save it as a file
ASM外部冗余是否可以替换磁盘
电商rpa是什么意思?跟电商rpi是一个意思吗?
ASM module in SAP Ecommerce Cloud Spartacus UI and Accelerator UI
【OpenCV】-边缘检测汇总示例
最近两个月谷歌 ad 掉的厉害
VBA输出日志到工作簿demo
busybox之reboot命令流程分析
[core]-ARMV7-A, ARMV8-A, ARMV9-A Architecture Introduction "Recommended Collection"
榕树贷款GPU 硬件架构
LRU缓存[线性表 -> 链表 -> hash定位 -> 双向链表]
架构实战营|模块8
PAT考试总结(考试心得)
跨境电商小知识之跨境电商物流定义以及方式讲解
The function of SQL GROUP BY dependence
2022年最新重庆建筑安全员模拟题库及答案