1. 程式人生 > 其它 >關於hutool工具箱進行RSA非對稱加密的使用筆記

關於hutool工具箱進行RSA非對稱加密的使用筆記

1.建立計算BMI指數的模組

def dun_bmi(person,height,weight):
print(person + "的身高" + str(height) + "米\t 體重:" + str(weight) + "千克" )
bmi = weight / (height * height)
print(person + "的bmi指數為: " + str(bmi))

2.匯入兩個包括同名函式的模組

def girth(width,height):
return (width + height) * 2
def area(width,heigth):
return width * heigth
if __name__ == '__main__':
print(area(10,20))
import math
PI = math.pi
def girth(r):
return round(2 * PI * r , 2)
def area(r):
return round(PI * r * r , 2)
if __name__ == '__main__':
print(girth(10))
import rectangle as r
import circular as c
if __name__ == '__main__':
print("圓形的周長是:", c.girth(10))
print("矩形的周長是:" , r.girth(10,20))

3.在指定包中建立通用的設定和獲取尺寸的模組

_width = 800
_height = 600
def change(w,h):
global _width
_width = w
global _height
_height = h
def getWidth():
global _width
return _width
def getHeight():
global _height
return _height
from settings.size import *
if __name__ == 'main__':
change(1024,768)
print("寬度: ",getWidth())
print("高度: ",getHeight())

4.生成由數字,字母組成的4位驗證碼

import random
if __name__ == '__main__':
checkcode = ''
for i in range(4):
index = random.randrange(0,4)
if index != i and index+1 != i:
checkcode += chr(random.randint(97,122))
elif index + 1 == i:
checkcode += chr(random.randint(65,90))
else:
checkcode += str(random.randint(1,9))
print("驗證碼: " ,checkcode)

實戰一:

import random
def number():
a=[random.randint(1,35) for i in range(5)]
l=[]
for i in a:
if i not in l:
l.append(i)
else:
i=random.randint(1,35)
l.append(i)
l.sort()
a=[str(i) for i in l]
b=[random.randint(1,12) for i in range(2)]
o=[]
for i in b:
if i not in o:
o.append(i)
else:
i=random.randint(1,12)
o.append(i)
o.sort()
b=[str(i) for i in o]
c=[" "*5]
for i in range(5):
if len(a[i])==2:
for j in range(2):
if len(b[j])==2:
pass
else:
b[j]='0'+b[j]
else:
a[i]='0'+a[i]
g=a+c+b
for i in g:
print(i,end=" ")
print("大樂透號碼生成器")
k=int(input("請輸入要生成的大樂透號碼注數:"))
for i in range(k):
number()
print("")

實戰二:

import sys

sys.path.append(r"D:\Python\python0\python0")

import JiFu
print('開始集福啦~~~')

fu={'愛國福':0,'富強福':0,'和諧福':0,'友善福':0,'敬業福':0}

while JiFu.five_blessings(fu)==0:
input('\n按下<Enter>鍵獲取五福')

Strfu=JiFu.Ji_Fu()[0]

print('獲取到:' +Strfu)

fu[Strfu] += 1

JiFu.fus(fu)
print('\n恭喜您整合五福!!!')



import random

def Ji_Fu():

fus=['愛國福','富強福','和諧福','友善福','敬業福']

fu=random.sample(fus, 1)

return fu

def fus(fu):
print('當前擁有的福:')

for i, j in fu.items():

print(i,': ',j,'\t',end='')

def five_blessings(fu):

type=1

for i, j in fu.items():

if j==0:

type=0

return type;

 實戰3

def net_play(time):
print('瀏覽網頁',str(time)+'小時')
return time
def Watch_videos(time):
print( '看視訊',str(time)+'小時')
return time
def Play_game(time):
print('玩網路遊戲',str(time)+'小時')
return time
def Study(time):
print( '上網學習',str(time)+'小時')
return time
def times(time):
if time>=8:
print('今天上網時間共計'+str(time)+'小時,請保護眼睛,合理安排上網時間!')
return time


import sys
sys.path.append(r"D:\Python\python0\python0")
import Net
name='小明'
time=0;
print(name,'上網時間、行為統計:')
time += Net.net_play(1.5)
time += Net.Watch_videos( 2)
time += Net.Play_game( 3)
time += Net.Study(2)
Net.times(time)
實戰四
import sys
sys.path.append(r"D:\Python\python0\python0")
import tax
monthMoney=int(input("請輸入月收入:"))
print("應納個人所得稅稅額為%.2f" % tax.tax(monthMoney))

def tax(monthMoney):
ds = 3500
threeInsurancesUp = 7662
yangLao = monthMoney * 0.08
yiLiao = monthMoney * 0.02
shiYe = monthMoney * 0.005
homeMoney = monthMoney * 0.12
threeInsurances = yangLao + yiLiao + shiYe + homeMoney
if threeInsurances > threeInsurancesUp:
threeInsurances = threeInsurancesUp
payable = monthMoney - threeInsurances - ds
single = 0
if payable < 1500:
single = payable * 0.03 - 0
elif payable >= 1500 and payable < 4500:
single = payable * 0.1 - 105
elif payable >= 4500 and payable < 9000:
single = payable * 0.2 - 555
elif payable >= 9000 and payable < 35000:
single = payable * 0.25 - 1005
elif payable >= 35000 and payable < 55000:
single = payable * 0.3 - 2002
elif payable >= 55000 and payable < 80000:
single = payable * 0.35 - 5505
elif payable >= 80000:
single = payable * 0.45 - 13505
if single < 0:
single = 0
return single