8th day of python challenges 105-110

This commit is contained in:
abd.shallal
2019-08-01 14:54:19 +03:00
parent dc946b9aba
commit 87e968da93
8 changed files with 210 additions and 161 deletions

View File

@@ -0,0 +1,3 @@
file = open('Numbers.txt', 'w')
file.write('1, 2, 3, 4, 5')
file.close()

View File

@@ -0,0 +1,7 @@
file = open('Names.txt', 'w')
file.write('Abdullah\n')
file.write('Ahmed\n')
file.write('Ali\n')
file.write('Yaser\n')
file.write('Hasanen\n')
file.close()

View File

@@ -0,0 +1,2 @@
file_open = open('Names.txt', 'r')
print(file_open.read())

View File

@@ -0,0 +1,9 @@
file_open = open('Names.txt', 'r')
print(file_open.read())
file_open.close()
ask = str(input('Enter a name to add to file : '))
file_write = open('Names.txt', 'a')
file_write.write(file_write + '\n')
file_write.close()
file_open = open('Names.txt', 'r')
print(file_open.read())

View File

@@ -0,0 +1,25 @@
count = 0
while count < 5:
print('1) Create a new file')
print('2) Display the file')
print('3) Add a new item to the file ')
selection_input = int(input('Make a selection 1, 2 or 3 : '))
if selection_input == 1:
file = open('Subject.txt', 'w')
subject_name = str(input('Enter school subject name : '))
file.write(subject_name + '\n')
file.close()
elif selection_input == 2:
file = open('Subject.txt', 'r')
print(file.read())
file.close()
elif selection_input == 3:
file = open('Subject.txt', 'a')
subject_name = str(input('Enter school subject name to add into file : '))
file.write(subject_name + '\n')
file.close()
count = count + 1
file = open('Subject.txt', 'r')
print(file.read())
file.close()

View File

@@ -0,0 +1,15 @@
file = open('Names.txt', 'r')
print(file.read())
file.close()
file2 = open('Names2.txt', 'w')
file2.close()
ask = str(input('Enter one of names : '))
with open('Names.txt', 'rt') as myFile:
for myLine in myFile:
if myLine != ask:
file2 = open('Names2.txt', 'a')
file2.write(myLine + '\n')
file2.close()
myFile.close()
file = open('Names2.txt', 'r')
print(file.read())