小编pan*_*kes的帖子

python - 如何在没有正则表达式的情况下检查字符串的要求?

我需要制作一个程序来检查具有以下要求的输入(密码):

  • 长度至少为 8 个字符
  • 包含至少一个小写字母
  • 包含至少一个大写字母
  • 包含至少一个数字

如果不满足任何要求,则应返回 false。

到目前为止,我仅针对第一个要求进行了以下操作。

def check_password(pword):
   if len(pword) < 8:
       return False
   for i in pword:
       if pword[i].isUpper():
           print(True)
   return True
Run Code Online (Sandbox Code Playgroud)

我不知道如何在不使用正则表达式的情况下实现其他要求。

python string passwords

1
推荐指数
1
解决办法
59
查看次数

python - np.random.random 四舍五入到小数点后一位

尝试使用以下方法生成数字np.random.random

for portfolio in range(2437):
    weights = np.random.random(3)
    weights /= np.sum(weights)

    print(weights)
Run Code Online (Sandbox Code Playgroud)

它按预期工作:

[0.348674 0.329747 0.321579]
[0.215606 0.074008 0.710386]
[0.350316 0.589782 0.059901]
[0.639651 0.025353 0.334996]
[0.697505 0.171061 0.131434]
.
.
.
.
Run Code Online (Sandbox Code Playgroud)

但是,我如何更改数字,使每行限制为 1 位小数,例如:

[0.1 0.2 0.7]
[0.2 0.2 0.6]
[0.5 0.4 0.1]
.
.
.
.
Run Code Online (Sandbox Code Playgroud)

python random numbers

0
推荐指数
1
解决办法
3600
查看次数

标签 统计

python ×2

numbers ×1

passwords ×1

random ×1

string ×1