最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python 窮舉指定長度的密碼例子

 更新時間:2020年04月02日 09:22:41   作者:lacoucou  
這篇文章主要介紹了python 窮舉指定長度的密碼例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

本程序可根據(jù)給定的字符字典,窮舉指定長度的所有字符串:

def get_pwd(str, num):
  if(num == 1):
   for x in str:
    yield x
  else:
   for x in str:
    for y in get_pwd(str, num-1):
     yield x+y
 
strKey="abc"
for x in get_pwd(strKey,3):
 print x

結(jié)果:

aaa
aab
aac
aba
abb
abc
aca
acb
acc
baa
bab
bac
bba
bbb
bbc
bca
bcb
bcc
caa
cab
cac
cba
cbb
cbc
cca
ccb
ccc

本程序占用內(nèi)存小,生成速度快,歡迎嘗試?。?!

補充知識:Python 窮舉法, 二分法 與牛頓-拉夫遜方法求解平方根的性能對比

窮舉法, 二分法 與牛頓-拉夫遜方法求解平方根的優(yōu)劣,從左到右依次遞優(yōu)。

經(jīng)過測試,窮舉法基本超過 1 分鐘,還沒有出數(shù)據(jù);

二分法只要區(qū)區(qū)1秒不到就出結(jié)果了。

牛頓-拉夫遜是秒出,沒有任何的停頓。

numberTarget =int(input("Please enter a number:"))
numberSqureRoot = 0
while(numberSqureRoot<abs(numberTarget)):
 if numberSqureRoot**2 >= abs(numberTarget):
  break
 numberSqureRoot = numberSqureRoot + 1

if numberSqureRoot**2 != numberTarget:
 print("Your number %s is not a perfect squre, the square root is %s " % ( numberTarget,numberSqureRoot) )
else:
 if numberTarget < 0 :
  numberSqureRoot = -numberSqureRoot
 print("Your number %s is a perfect squre, the square root is %s " % ( numberTarget, numberSqureRoot))

print("now we begin to calculate the binary search...")

numberTarget=int(input("Please enter the number for binary search..."))
numberSqureRoot = 0

lowValue = 0.0
highValue=numberTarget*1.0

epsilon = 0.01
numberSqureRoot = (highValue + lowValue)/2

while abs(numberSqureRoot**2 - numberTarget) >=epsilon:
 print("lowValue:%s, highValue:%s, currentValue:%s"%(lowValue,highValue,numberSqureRoot))
 if numberSqureRoot**2<numberTarget:
  lowValue=numberSqureRoot
 else:
  highValue=numberSqureRoot
 numberSqureRoot = (lowValue+highValue) /2

print("The number %s has the squre root as %s " %(numberTarget,numberSqureRoot))


print("now we begin to calculate the newTon search...")

numberTarget=int(input("Please enter the number for newTon search..."))
numberSqureRoot = 0

epsilon = 0.01
k=numberTarget
numberSqureRoot = k/2.0

while( abs(numberSqureRoot*numberSqureRoot - k)>=epsilon):
 numberSqureRoot=numberSqureRoot-(((numberSqureRoot**2) - k)/(2*numberSqureRoot))

print("squre root of %s is %s " %(numberTarget,numberSqureRoot))

以上這篇python 窮舉指定長度的密碼例子就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python實現(xiàn)PS濾鏡特效之扇形變換效果示例

    Python實現(xiàn)PS濾鏡特效之扇形變換效果示例

    這篇文章主要介紹了Python實現(xiàn)PS濾鏡特效之扇形變換效果,結(jié)合實例形式分析了Python實現(xiàn)PS濾鏡扇形變換效果的原理與相關(guān)操作技巧,需要的朋友可以參考下
    2018-01-01
  • Python實現(xiàn)的金山快盤的簽到程序

    Python實現(xiàn)的金山快盤的簽到程序

    正在學(xué)習(xí)python而且自己一直在用金山快盤,所以就寫來個簽到的功能,每天定時跑
    2013-01-01
  • Python按條件刪除Excel表格數(shù)據(jù)的方法(示例詳解)

    Python按條件刪除Excel表格數(shù)據(jù)的方法(示例詳解)

    本文介紹基于Python語言,讀取Excel表格文件,基于我們給定的規(guī)則,對其中的數(shù)據(jù)加以篩選,將不在指定數(shù)據(jù)范圍內(nèi)的數(shù)據(jù)剔除,保留符合我們需要的數(shù)據(jù)的方法,感興趣的朋友跟隨小編一起看看吧
    2024-08-08
  • Python開發(fā)桌面小程序功能

    Python開發(fā)桌面小程序功能

    這篇文章主要介紹了Python開發(fā)一個桌面小程序功能,開發(fā)環(huán)境界面設(shè)置,功能介紹結(jié)合示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04
  • python如何修改圖像的分辨率

    python如何修改圖像的分辨率

    這篇文章主要介紹了python如何修改圖像的分辨率問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • Python 70行代碼實現(xiàn)簡單算式計算器解析

    Python 70行代碼實現(xiàn)簡單算式計算器解析

    這篇文章主要介紹了Python 70行代碼實現(xiàn)簡單算式計算器解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-08-08
  • Python寫代碼的七條重要技巧介紹

    Python寫代碼的七條重要技巧介紹

    大家好,本篇文章主要講的是Python寫代碼的七條重要技巧介紹,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • Python中zip()函數(shù)的解釋和可視化(實例詳解)

    Python中zip()函數(shù)的解釋和可視化(實例詳解)

    zip() 函數(shù)用于將可迭代的對象作為參數(shù),將對象中對應(yīng)的元素打包成一個個元組,然后返回由這些元組組成的列表。這篇文章主要介紹了Python中zip()函數(shù)的解釋和可視化,需要的朋友可以參考下
    2020-02-02
  • Python循環(huán)語句之break與continue的用法

    Python循環(huán)語句之break與continue的用法

    這篇文章主要介紹了Python循環(huán)語句之break與continue的用法,是Python入門學(xué)習(xí)中的基礎(chǔ)知識,需要的朋友可以參考下
    2015-10-10
  • python中as用法實例分析

    python中as用法實例分析

    這篇文章主要介紹了python中as用法,實例分析了as的功能及相關(guān)使用技巧,非常具有實用價值,需要的朋友可以參考下
    2015-04-04

最新評論

西峡县| 陇南市| 岳池县| 泽普县| 平湖市| 依安县| 尤溪县| 平罗县| 孟村| 蒲城县| 盐山县| 大港区| 合江县| 德清县| 屏山县| 沽源县| 龙山县| 宝清县| 井冈山市| 桃源县| 建瓯市| 桐庐县| 凉城县| 融水| 潢川县| 唐山市| 永兴县| 瓮安县| 江口县| 乐都县| 荥阳市| 克东县| 昌都县| 满城县| 绥宁县| 兰坪| 霞浦县| 大竹县| 东乡族自治县| 峡江县| 龙胜|