-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment20.py
More file actions
34 lines (28 loc) · 1 KB
/
Copy pathAssignment20.py
File metadata and controls
34 lines (28 loc) · 1 KB
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
32
33
34
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 12 10:32:48 2018
@author: bjwil
"""
import os
os.chdir('C:\\Users\\bjwil\\Python College Course')
name = input("What would you like me to name your file as? Do NOT include the extension .txt or any other extension! ")
name = name + '.txt'
text = list('Hello World This is your conscience talking Now is the time to relax and reminiscence'.split())
with open(name, 'a') as file_:
for word in text:
print(word, file = file_, end = '\n')
print('Closing ... ' + name)
print("===========================")
print('Opening ... ' + name)
newText = input('What sentence should I add to the last line of the file? ')
newText = list(newText.split())
with open(name, 'a') as file_:
for word in newText:
print(word, file = file_, end = '\n')
print('Closing ... ' + name)
print("===========================")
print('Opening ... ' + name)
with open(name, 'r') as file_:
alist = [line.rstrip() for line in file_]
for word in alist:
print(word)