1. You prepare a .txt file with about 5-10 student names. One name per line, e.g
ID: 3740696 • Letter: 1
Question
1. You prepare a .txt file with about 5-10 student names. One name per line, e.g.: Grace Deng. Save it as you like, on a location you preferred (very important to know the location of this file.)
2. You prepare an EMPTY .txt file. Save it as you like, on a location you preferred (very important to know the location of this file.)
3. Revise the userfile.py (Page 157) to to generate some kind of student email address at WIU, let's see it should be: y-deng@wiu.edu, by using first letter of first name and last name (no more than 7 letters long).
So this userfile_v2.py you created can do the batch user email address process.
4. What to submit?
a .txt file with about 5-10 student names;
a .txt file with about 5-10 student email address;
a revised userfile_v2.py copy/pasted on .txt file.
(so you will have 3 .txt file attached separately.)
Explanation / Answer
Hello There,
Please find the requested files below after execution of the script and the script execution itself
names.txt
------------------
Jack Leach
Tim Armstrong
Jade Smith
John Mcenroy
Tim Paine
Christian Reed
---------------------------------
userfile_v2.py
-----------------------------------
#!/usr/bin/env python
with open("names.txt", 'r') as names, open("EMPTY.txt", 'w') as emails:
for line in names:
x=line.rstrip(' ').split(' ')
mail=(x[0][0]+'-'+x[1][:5]+'@wiu.edu').lower()
emails.write(mail+' ')
---------------------------------
EMPTY.txt
------------------------------
j-leach@wiu.edu
t-armst@wiu.edu
j-smith@wiu.edu
j-mcenr@wiu.edu
t-paine@wiu.edu
c-reed@wiu.edu
-----------------------------
Script Execution:
----------------------------
$ cat names.txt
Jack Leach
Tim Armstrong
Jade Smith
John Mcenroy
Tim Paine
Christian Reed
$ cat EMPTY.txt
$ cat userfile_v2.py
#!/usr/bin/env python
with open("names.txt", 'r') as names, open("EMPTY.txt", 'w') as emails:
for line in names:
x=line.rstrip(' ').split(' ')
mail=(x[0][0]+'-'+x[1][:5]+'@wiu.edu').lower()
emails.write(mail+' ')
$ ./userfile_v2.py
$ cat EMPTY.txt
j-leach@wiu.edu
t-armst@wiu.edu
j-smith@wiu.edu
j-mcenr@wiu.edu
t-paine@wiu.edu
c-reed@wiu.edu
$
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.