-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserfile.py
More file actions
31 lines (24 loc) · 873 Bytes
/
userfile.py
File metadata and controls
31 lines (24 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# userfile.py
# Program to create a file of usernames in batch mode.
def main():
print("This program creates a file of usernames from a")
print("file of names.")
# get the file names
infileName = input("What file are the names in? ")
outfileName = input("What file should the usernames go in? ")
# open the files
infile = open(infileName, "r")
outfile = open(outfileName, "w")
# process each line of the input file
for line in infile:
# get the first and last names from line
first, last = line.split()
# create the username
uname = (first[0]+last[:7]).lower()
# write it to the output file
print(uname, file=outfile)
# close both files
infile.close()
outfile.close()
print("Usernames have been written to", outfileName)
main()