运行并选择密码强度后,“密码”中没有任何内容。 另外,有没有办法避免为每个password_strength级别制作5个if循环?
import string
import random
def password_generator() :
password_strength = [1,2,3,4,5]
password = []
user_choice = input("Enter desired password strength (1-5) : ")
if user_choice == password_strength[0] :
password_length = 4
for i in range(0, password_length) :
password.append(chr(random.randint(33,126)))
print(password)
password_generator()
答案 0 :(得分:0)
这是错误的行,将您的输入转换为整数。
import socket
def main():
HOST, PORT = "192.168.xx.xx", 7799
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect((HOST, PORT))
data = (sock.recv(1024)).decode('utf-8')
with open('imageNames2.txt', 'w') as file:
try:
while data:
print(data)
file.write(data)
data = (sock.recv(1024)).decode('utf-8')
except Exception as e:
print(e)
if __name__ == '__main__':
main()