Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions Seth_A99501/day21.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The content is:\n",
"Accountability Communication Organisation \n"
]
}
],
"source": [
"#read and display data\n",
"FileName=\"notes3.txt\"\n",
"with open(FileName,'r') as file:\n",
" content=file.read()\n",
" print('The content is:')\n",
" print(content)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The content is:\n",
" AIESEC’s core-work is very relevant in the Middle East to promote cross cultural understanding as a pathway to peace.\n"
]
}
],
"source": [
"FileName=\"notes2.txt\"\n",
"with open(FileName,'r') as file:\n",
" content=file.read()\n",
" print('The content is:')\n",
" print(content)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The content is:\n",
"Accountability Communication Organisation \n"
]
}
],
"source": [
"FileName=\"notes3.txt\"\n",
"with open(FileName,'r') as file:\n",
" content=file.read()\n",
" print('The content is:')\n",
" print(content)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#write user input to a text file\n",
"file_name=\"test.txt\"\n",
"user_input=input(\"Write your notes:\")\n",
"with open(file_name, \"w\") as file:\n",
" file.write(user_input)\n",
" print('Succefully save to',file_name)\n",
" \n",
"#read and display user \n",
"file_name=\"notes3.txt\"\n",
"with open(file_name,'r') as file:\n",
" content=file.read()\n",
" print('The content of the file saved is')\n",
" print(content)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The consolidated file is:\n",
"AIESEC is a platform to face fears in order to eradicate prejudices and discrimination. AIESEC’s core-work is very relevant in the Middle East to promote cross cultural understanding as a pathway to peace.Accountability Communication Organisation \n"
]
}
],
"source": [
"#write data from three differents files\n",
"inputFiles=[\"notes1.txt\",\"notes2.txt\",\"notes3.txt\"]\n",
"outputFile=\"consolidated.txt\"\n",
"with open(outputFile,'w') as file:\n",
" #loop through each file and write too file\n",
" for content in inputFiles:\n",
" with open(content,'r') as files:\n",
" textContent=files.read()\n",
" file.write(textContent)\n",
"#read and display the output file\n",
"with open(outputFile, 'r') as file:\n",
" print(\"The consolidated file is:\") \n",
" print(file.read())\n"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}