红包分配算法代码实现发给大家,祝红包大丰收!
#coding=gbk import random import sys #print random.randint(0, 99) #print "====", random.uniform(0, 0.99) def calRandomValue(min, max, total, num): print min, max, total, num total = float(total) num = int(num) min = 0.01 if(num return if num == 1: print "第%d个人拿到红包数为:%.2f" %(num, total) return i = 1 total_money = total #rtotal = (total*100 - min*num*100)/100 while( i max = total_money - min*(num- i) k = int((num-i)/2) if num -i k = num -i max = max/k monney = random.randint(int(min*100), int(max*100)) monney = float(monney)/100 total_money = total_money - monney print "第%d个人拿到红包数为:%.2f, 余额为: %.2f" %(i, monney, total_money) i += 1 print "第%d个人拿到红包数为:%.2f, 余额为: %.2f" %(i, total_money, 0.0) if __name__ == "__main__": min = sys.argv[1] max = sys.argv[2] total = sys.argv[3] num = sys.argv[4] calRandomValue(min, max, total, num)
python 2.py 0.01 10 20 30
0.01 10 20 30
第1个人拿到红包数为:1.34, 余额为: 18.66
第2个人拿到红包数为:1.06, 余额为: 17.60
第3个人拿到红包数为:1.08, 余额为: 16.52
第4个人拿到红包数为:0.98, 余额为: 15.54
第5个人拿到红包数为:0.88, 余额为: 14.66
第6个人拿到红包数为:0.48, 余额为: 14.18
第7个人拿到红包数为:0.26, 余额为: 13.92
第8个人拿到红包数为:0.90, 余额为: 13.02
第9个人拿到红包数为:0.12, 余额为: 12.90
第10个人拿到红包数为:0.41, 余额为: 12.49
第11个人拿到红包数为:0.43, 余额为: 12.06
第12个人拿到红包数为:0.63, 余额为: 11.43
第13个人拿到红包数为:0.36, 余额为: 11.07
第14个人拿到红包数为:0.25, 余额为: 10.82
第15个人拿到红包数为:1.38, 余额为: 9.44
第16个人拿到红包数为:0.17, 余额为: 9.27
第17个人拿到红包数为:0.79, 余额为: 8.48
第18个人拿到红包数为:0.52, 余额为: 7.96
第19个人拿到红包数为:0.44, 余额为: 7.52
第20个人拿到红包数为:1.15, 余额为: 6.37
第21个人拿到红包数为:0.13, 余额为: 6.24
第22个人拿到红包数为:0.76, 余额为: 5.48
第23个人拿到红包数为:1.32, 余额为: 4.16
第24个人拿到红包数为:0.80, 余额为: 3.36
第25个人拿到红包数为:0.16, 余额为: 3.20
第26个人拿到红包数为:0.27, 余额为: 2.93
第27个人拿到红包数为:1.82, 余额为: 1.11
第28个人拿到红包数为:0.45, 余额为: 0.66
第29个人拿到红包数为:0.27, 余额为: 0.39
第30个人拿到红包数为:0.39, 余额为: 0.00
以上所述就是本文的全部内容了,希望大家能够喜欢。

pythonuseshybridapprace,ComminingCompilationTobyTecoDeAndInterpretation.1)codeiscompiledtoplatform-Indepententbybytecode.2)bytecodeisisterpretedbybythepbybythepythonvirtualmachine,增強效率和通用性。

theKeyDifferencesBetnewpython's“ for”和“ for”和“ loopsare:1)” for“ loopsareIdealForiteringSequenceSquencesSorkNowniterations,而2)”,而“ loopsareBetterforConterContinuingUntilacTientInditionIntionismetismetistismetistwithOutpredefinedInedIterations.un

在Python中,可以通過多種方法連接列表並管理重複元素:1)使用 運算符或extend()方法可以保留所有重複元素;2)轉換為集合再轉回列表可以去除所有重複元素,但會丟失原有順序;3)使用循環或列表推導式結合集合可以去除重複元素並保持原有順序。

fasteStmethodMethodMethodConcatenationInpythondependersonListsize:1)forsmalllists,operatorseffited.2)forlargerlists,list.extend.extend()orlistComprechensionfaster,withextendEffaster,withExtendEffers,withextend()withextend()是extextend()asmoremory-ememory-emmoremory-emmoremory-emmodifyinginglistsin-place-place-place。

toInSerteLementIntoApythonList,useAppend()toaddtotheend,insert()foreSpificPosition,andextend()formultiplelements.1)useappend()foraddingsingleitemstotheend.2)useAddingsingLeitemStotheend.2)useeapecificindex,toadapecificindex,toadaSpecificIndex,toadaSpecificIndex,blyit'ssssssslorist.3 toaddextext.3

pythonlistsareimplementedasdynamicarrays,notlinkedlists.1)他們areStoredIncoNtiguulMemoryBlocks,mayrequireRealLealLocationWhenAppendingItems,EmpactingPerformance.2)LinkesedlistSwoldOfferefeRefeRefeRefeRefficeInsertions/DeletionsButslowerIndexeDexedAccess,Lestpypytypypytypypytypy

pythonoffersFourmainMethodStoreMoveElement Fromalist:1)刪除(值)emovesthefirstoccurrenceofavalue,2)pop(index)emovesanderturnsanelementataSpecifiedIndex,3)delstatementremoveselemsbybybyselementbybyindexorslicebybyindexorslice,and 4)

toresolvea“ dermissionded”錯誤Whenrunningascript,跟隨台詞:1)CheckAndAdjustTheScript'Spermissions ofchmod xmyscript.shtomakeitexecutable.2)nesureThEseRethEserethescriptistriptocriptibationalocatiforecationAdirectorywherewhereyOuhaveWritePerMissionsyOuhaveWritePermissionsyYouHaveWritePermissions,susteSyAsyOURHomeRecretectory。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!