【程式碼題python】:將n元錢隨機分給m個人,每個人最少0.01。輸入m、n,輸出長度為m的陣列。
題目
將n元錢隨機分給m個人,每個人最少0.01。輸入m、n,輸出長度為m的陣列。例如輸入10.00,2,輸出[8.17,1.83]
程式碼
import random
result = []
def hb(n, m):
for i in range(m - 1):
result.append(random.uniform(0.01, n - sum(result)))
result.append(n - sum(result))
return result
print(hb(10, 3))
結果
相關推薦
【程式碼題python】:將n元錢隨機分給m個人,每個人最少0.01。輸入m、n,輸出長度為m的陣列。
技術標籤:pythonpython 題目 將n元錢隨機分給m個人,每個人最少0.01。輸入m、n,輸出長度為m的陣列。例如輸入10.00,2,輸出[8.17,1.83]
【程式碼題python】:一個列表[1,2,5,3,2,5,7,8,9,11,2,33,44,51,4,7,9],請去除重複數字並輸出去除後新的列表
技術標籤:pythonpython 題目 一個列表[1,2,5,3,2,5,7,8,9,11,2,33,44,51,4,7,9],請去除重複數字並輸出去除後新的列表 程式碼
【程式碼題python】【leetcode】:最長迴文串
技術標籤:pythonleetcodepython 題目 給定一個字串 s,找到 s 中最長的迴文子串 迴文串示例:abcba 給定字串:sssabcba1da
【程式碼題python】【leetcode】找到字串的最長無重複字元子串
技術標籤:python演算法pythonleetcode 參考:https://blog.csdn.net/qq_34771726/article/details/88643476 給定一個數組arr,返回arr的最長無的重複子串的長度(無重複指的是所有數字都不相同)。 示例一示例二程
【做題記錄】洛谷P6862 [RC-03] 隨機樹生成器
洛谷P6862 Problem 洛谷P6862 [RC-03] 隨機樹生成器 題目大意: 有 \\(T\\) 組資料。 有一個隨機樹生成器,對於給定的 \\(n\\),會生成一棵 \\(n\\) 個點的有根樹。其中,第 \\(i\\) 個點(\\(1 < i\\))等概率
基類使用私有資料_【進階Python】第七講:介面與抽象基類
技術標籤:基類使用私有資料怎麼檢視抽象方法被哪些類繼承 點選藍字關注我
for 迴圈語句基本用法及示例_【文山玩Python】迴圈語句:用for語句迴圈一切可遍歷物件...
技術標籤:for 迴圈語句基本用法及示例 for in不僅可以使用range()函式來產生多次迴圈,也可以用來迴圈其它資料型別,比如用for來迴圈字串:
Linux從頭學06:16張結構圖,徹底理解【程式碼重定位】的底層原理
作者:道哥,10+年的嵌入式開發老兵。 公眾號:【IOT物聯網小鎮】,專注於:C/C++、Linux作業系統、應用程式設計、物聯網、微控制器和嵌入式開發等領域。公眾號回覆【書籍】,獲取 Linux、嵌入式領域經典書籍。
【PTA|Python】浙大版《Python 程式設計》題目集:第二章
前言 Hello!小夥伴! 非常感謝您閱讀海轟的文章,倘若文中有錯誤的地方,歡迎您指出~
【華為OD機試真題 python】日誌首次上報最多積分【2022 Q4 | 100分】
Override the entrypoint of an image Introduced in GitLab and GitLab Runner 9.4. Read more about the extended configuration options.
【刷題-LeetCode】165 Compare Version Numbers
Compare Version Numbers Compare two version numbers version1 and version2. If *version1* > *version2* return 1; if *version1* < *version2* return -1;otherwise return 0.
【刷題-LeetCode】179 Largest Number
Largest Number Given a list of non negative integers, arrange them such that they form the largest number.
【刷題-LeetCode】122 Best Time to Buy and Sell Stock II
Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a given stock on day i.
【刷題-LeetCode】123 Best Time to Buy and Sell Stock III
Best Time to Buy and Sell Stock III Say you have an array for which the ith element is the price of a given stock on day i.
【刷題-LeetCode】191 Number of 1 Bits
Number of 1 Bits Write a function that takes an unsigned integer and return the number of \'1\' bits it has (also known as the Hamming weight).
【刷題-LeetCode】199 Binary Tree Right Side View
Binary Tree Right Side View Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
【刷題-LeetCode】200 Number of Islands
Number of Islands Given a 2d grid map of \'1\'s (land) and \'0\'s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or ve
【刷題-LeetCode】201 Bitwise AND of Numbers Range
Bitwise AND of Numbers Range Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.
【刷題-LeetCode】204. Count Primes
Count Primes Count the number of prime numbers less than a non-negative number, *n*. Example: Input: 10 Output: 4
【刷題-LeetCode】208. Implement Trie (Prefix Tree)
Implement Trie (Prefix Tree) Implement a trie with insert, search, and startsWith methods. Example: Trie trie = new Trie();