gpt4 book ai didi

python - 如何制作随机电子邮件生成器?

转载 作者:行者123 更新时间:2023-12-04 14:37:27 26 4
gpt4 key购买 nike

我想这样做,所以我从我的列表中随机收到 7 个字母并将其制作成随机电子邮件,但是我无法让它一次只打印 1 个字母的完整电子邮件。

import random

letters = ["a", "b","c", "d","e", "f","g", "h","i", "j","k", "l","m", "n",
"o", "p","q", "r","s", "t","u", "v","w", "x","y", "z",]

random1 = random.choice(letters)

for x in random1(7):
print (x+"@gmail.com")

这只会给我一个错误,如果我修复它,它只会给我一封电子邮件。修复方法是:
random1 = random.choice(letters)
print (random1+"@gmail.com")

最佳答案

请尝试以下操作:

import random
import string

def random_char(char_num):
return ''.join(random.choice(string.ascii_letters) for _ in range(char_num))

print (random_char(7)+"@gmail.com")
您可以使用 string.ascii_lowercase如果你只想要小写字母

关于python - 如何制作随机电子邮件生成器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59231343/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com