当前位置:网站首页>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)
边栏推荐
猜你喜欢
串的基本概念与操作
anaconda虚拟环境安装pytorch gpu版本
Character Functions and String Functions
给你一个大厂面试的机会,你能面试上吗?进来看看!
DCM middleware family welcomes a new member
Acwing第 62 场周赛【未完结】
Different lower_case_table_names settings for server (‘1‘) and data dictionary (‘0‘) 解决方案
【OpenCV】-边缘检测汇总示例
Exploring Plain Vision Transformer Backbones for Object Detection Paper Reading Notes
想吃菌子,当然是自己上山找了
随机推荐
Selenium自动化测试之Selenium IDE
基本语法(一)
带有对称约束切换线性系统的结构可控性
ASM module in SAP Ecommerce Cloud Spartacus UI and Accelerator UI
ipv4和ipv6对比(IPV4)
榕树贷款GPU 硬件架构
ESP8266-Arduino编程实例-MCP9808数字温度传感器驱动
A40i/T3 uboot启动时对PMU部分初始化
连续变量离散化教程
alert(1) (haozi.me)靶场练习
CWE4.8 -- 2022年危害最大的25种软件安全问题
file contains vulnerabilities
The function of SQL GROUP BY dependence
建情人节表白网站(超详细过程,包教包会)
电商rpa是什么意思?跟电商rpi是一个意思吗?
0x80070570文件或目录损坏且无法删除(0x80070091怎么删除)
Comparison of ipv4 and ipv6 (IPV4)
荣耀手机参数写错,客服认为没错
三六零与公安部三所发布报告:关基设施保护成为网络安全博弈关键
kernel syscore