我试图在 python 的 for 循环中将每个字母并排打印出来。请帮我
I am trying to print each alphabet beside eachother in a for loop in python. Please help me
好的,所以我在 python 中创建了一个密码生成器,我正在尝试创建一个安全的密码,它会像这样显示在控制台中:
Fdm6:yguiI
我还希望用户指定密码所需的字母数(这确实有效)
无论如何,这是代码
import random
options = '1234567890!@#$%^&*()`~-_=+\|]}[{\'";:/?.>,<QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm'
char_list = tuple(options)
print("""Password checker
This either checks your password or creates a sequre password.
Your commands are \"create password\" and \"check password\"""")
command = str(input('Type your command: '))
if command.lower() == 'create password':
digit_count = int(input('How many digits do you want your password to be? (Must be more than five and under 35): '))
if digit_count >= 5 and digit_count <= 35:
for i in range(digit_count):
password = random.choice(char_list)
print(password)
else:
print('Bruh I told you to give more than 5 or under 35')
现在,输出是这样的
有人请帮助我
替换这部分
for i in range(digit_count):
password = random.choice(char_list)
print(password)
与:
password = ''.join(random.choices(char_list, k=digit_count))
print(password)
在输出打印语句中添加一个 end
参数 -
for i in range(digit_count):
password = random.choice(char_list)
print(password,end='')
默认情况下,end
等于'\n'。因此,如果您未将结尾指定为 ''(空)
,它会更改行
如果确实要存储密码,请使用列表推导式 -
p = [random.choice(char_list) for i in range(digit_count)]
password = ''.join(p) # Or, you could just write this into a single line
print(password)
好的,所以我在 python 中创建了一个密码生成器,我正在尝试创建一个安全的密码,它会像这样显示在控制台中:
Fdm6:yguiI
我还希望用户指定密码所需的字母数(这确实有效)
无论如何,这是代码
import random
options = '1234567890!@#$%^&*()`~-_=+\|]}[{\'";:/?.>,<QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm'
char_list = tuple(options)
print("""Password checker
This either checks your password or creates a sequre password.
Your commands are \"create password\" and \"check password\"""")
command = str(input('Type your command: '))
if command.lower() == 'create password':
digit_count = int(input('How many digits do you want your password to be? (Must be more than five and under 35): '))
if digit_count >= 5 and digit_count <= 35:
for i in range(digit_count):
password = random.choice(char_list)
print(password)
else:
print('Bruh I told you to give more than 5 or under 35')
现在,输出是这样的
有人请帮助我
替换这部分
for i in range(digit_count):
password = random.choice(char_list)
print(password)
与:
password = ''.join(random.choices(char_list, k=digit_count))
print(password)
在输出打印语句中添加一个 end
参数 -
for i in range(digit_count):
password = random.choice(char_list)
print(password,end='')
默认情况下,end
等于'\n'。因此,如果您未将结尾指定为 ''(空)
如果确实要存储密码,请使用列表推导式 -
p = [random.choice(char_list) for i in range(digit_count)]
password = ''.join(p) # Or, you could just write this into a single line
print(password)