Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

my name #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
168 changes: 168 additions & 0 deletions HW1_吳冠穎/HW1_吳冠穎.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"There are 539 sentences in HW1.txt. 169 of them include !?+-.\n",
"length before trim after trim\n",
"<=40 33 43\n",
"<=50 173 203\n",
"<=60 154 141\n",
"<=70 114 112\n",
"<=80 55 39\n",
" >80 10 1\n"
]
}
],
"source": [
"a=[] #before\n",
"\n",
"a1=0\n",
"a2=0\n",
"a3=0\n",
"a4=0\n",
"a5=0\n",
"a6=0\n",
"\n",
"b=[] #after\n",
"\n",
"b1=0\n",
"b2=0\n",
"b3=0\n",
"b4=0\n",
"b5=0\n",
"b6=0\n",
"\n",
"char=\"!?+-\"\n",
"c1=0\n",
"\n",
"with open('/home/allen890205/2022summer-git-python_basics/HW1/HW1.txt','r')as f:\n",
" line1=f.readlines()\n",
" count=len(line1)\n",
" #print(count) #總行數為539\n",
"\n",
"\n",
"for i in range(539):\n",
" a.append(len(line1[i])-1) \n",
"\n",
"a[538]=a[538]+1\n",
"\n",
"for i in range(539):\n",
" if (a[i]<=40):\n",
" a1=a1+1\n",
" if (a[i]>40 and a[i]<=50):\n",
" a2=a2+1\n",
" if (a[i]>50 and a[i]<=60):\n",
" a3=a3+1\n",
" if (a[i]>60 and a[i]<=70):\n",
" a4=a4+1\n",
" if (a[i]>70 and a[i]<=80):\n",
" a5=a5+1\n",
" if(a[i]>80):\n",
" a6=a6+1\n",
"\n",
"with open ('/home/allen890205/2022summer-git-python_basics/HW1/HW1.txt','r')as f:\n",
" line2 = f.readlines()\n",
" for i in range(539):\n",
" for x in range(len(char)):\n",
" if (char[x] in line2[i]):\n",
" c1=c1+1\n",
" break\n",
"\n",
"\n",
"for n in range(539):\n",
" for x in range(len(char)):\n",
" line2[n]=line2[n].replace(char[x],\"\")\n",
"\n",
"for i in range(539): \n",
" b.append(len(line2[i])-1) \n",
" \n",
"count1=len(line2)\n",
"b[538]=b[538]+1 \n",
"\n",
"for i in range(539): \n",
" if (b[i]<=40):\n",
" b1=b1+1\n",
" if (b[i]<=50 and b[i]>40):\n",
" b2=b2+1\n",
" if (b[i]>50 and b[i]<=60):\n",
" b3=b3+1\n",
" if (b[i]>60 and b[i]<=70):\n",
" b4=b4+1\n",
" if (b[i]>70 and b[i]<=80):\n",
" b5=b5+1\n",
" if (b[i]>80):\n",
" b6=b6+1\n",
"\n",
"\n",
"print('There are' ,count,'sentences in HW1.txt.',c1, 'of them include !?+-.')\n",
"print('length before trim after trim')\n",
"print('<=40',' ',a1,' ',b1)\n",
"print('<=50',' ',a2,' ',b2)\n",
"print('<=60',' ',a3,' ',b3)\n",
"print('<=70',' ',a4,' ',b4)\n",
"print('<=80',' ',a5,' ',b5)\n",
"print(' >80',' ',a6,' ',b6)\n",
"\n",
"aa1=str(a1)\n",
"aa2=str(a2)\n",
"aa3=str(a3)\n",
"aa4=str(a4)\n",
"aa5=str(a5)\n",
"aa6=str(a6)\n",
"bb1=str(b1)\n",
"bb2=str(b2)\n",
"bb3=str(b3)\n",
"bb4=str(b4)\n",
"bb5=str(b5)\n",
"bb6=str(b6)\n",
"cc1=str(c1)\n",
"count11=str(count)\n",
"\n",
"with open('/home/allen890205/2022summer-git-python_basics/HW1_吳冠穎/HW1_吳冠穎.txt','w') as f:\n",
" f.write('There are' +count11+'sentences in HW1.txt.'+cc1+ 'of them include !?+-.'+'\\n' )\n",
" f.write('length before trim after trim'+'\\n')\n",
" f.write('<=40'+' '+aa1+' '+bb1+'\\n')\n",
" f.write('<=50'+' '+aa2+' '+bb2+'\\n')\n",
" f.write('<=60'+' '+aa3+' '+bb3+'\\n')\n",
" f.write('<=70'+' '+aa4+' '+bb4+'\\n')\n",
" f.write('<=80'+' '+aa5+' '+bb5+'\\n')\n",
" f.write(' >80'+' '+aa6+' '+bb6+'\\n')\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.12 ('base': conda)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "fb5222317208a3638c995914365f4dbcb94bb2894d4dcc3e3ae37926e73377f8"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
8 changes: 8 additions & 0 deletions HW1_吳冠穎/HW1_吳冠穎.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
There are539sentences in HW1.txt.169of them include !?+-.
length before trim after trim
<=40 33 43
<=50 173 203
<=60 154 141
<=70 114 112
<=80 55 39
>80 10 1
1 change: 1 addition & 0 deletions name.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5j5gj5g5y