-1

I made a code which prints random emails. Now I want these emails in a text file. Here's my code:

import random
domain = ["@gmail.com", "@hotmail.com", "@outlook.com", "@yahoo.in", "@protonmail.com"]
names = ["John", "Leonardo", "Russel", "Danny", "Mac", "Fredrick", "Mark"]
for i in range(10):
   randname = random.randrange(len(names))
   randmail = random.randrange(len(domain))
   print(names[randname] + domain[randmail])
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
R123
  • 21
  • 2

1 Answers1

0

This will create a textFile.txt and add all your random emails to the file.

import random
domain = ["@gmail.com", "@hotmail.com", "@outlook.com", "@yahoo.in", "@protonmail.com"]
names = ["John", "Leonardo", "Russel", "Danny", "Mac", "Fredrick", "Mark"]
TxtFile = open("textFile.txt","w")
for i in range(10):
   randname = random.randrange(len(names))
   randmail = random.randrange(len(domain))
   print(names[randname] + domain[randmail])
   TxtFile.write(names[randname] + domain[randmail]+"\n")
TxtFile.close()
Sundeep Pidugu
  • 2,377
  • 2
  • 21
  • 43