[英]How to create L lists of n non-zero random decimals where each list sums to 1.0?
[英]How to format a number up to N decimals where N is random
我想加密一个最多N
小数的数字。 我使用的过程有时产生的小数小于N
所以我需要用左边的零填充其余部分。 我试过这个:
N = 5 # The number of decimals needed for encryption
encrypted = '%0Nd' % (x) # here x is a number used to encrypte the original number
但encrypted
N
应该是一个修正的数字。
encrypted = '{:0{width}d}'.format(x, width=N)
Python 3.6解决方案与格式字符串:
encrypted = f'{d:0{N}}'
例如,
>>> d = 5
>>> N = 3
>>> f'{d:0{width}}'
005
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.