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
360 changes: 360 additions & 0 deletions PythonBasics.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,360 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\"It's a string\""
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\"It's a string\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"salman\n"
]
}
],
"source": [
"print(\"salman\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "Missing parentheses in call to 'print'. Did you mean print(\"-\" * 20)? (<ipython-input-9-482f71f884c3>, line 4)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-9-482f71f884c3>\"\u001b[0;36m, line \u001b[0;32m4\u001b[0m\n\u001b[0;31m print \"-\" * 20\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m Missing parentheses in call to 'print'. Did you mean print(\"-\" * 20)?\n"
]
}
],
"source": [
"table = 8\n",
"start = 1\n",
"max = 10\n",
"print \"-\" * 20\n",
"print \"The table of 8\"\n",
"print \"-\" * 20\n",
"i = start\n",
"while i <= max:\n",
" result = i * table\n",
" print i, \" * \", table, \" =\" , result\n",
" i = i + 1\n",
"print \"-\" * 20\n",
"print \"Done counting...\"\n",
"print \"-\" * 20"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--------------------\n",
"The table of 8\n",
"--------------------\n",
"1 * 8 = 8\n",
"2 * 8 = 16\n",
"3 * 8 = 24\n",
"4 * 8 = 32\n",
"5 * 8 = 40\n",
"6 * 8 = 48\n",
"7 * 8 = 56\n",
"8 * 8 = 64\n",
"9 * 8 = 72\n",
"10 * 8 = 80\n",
"--------------------\n",
"Done counting...\n",
"--------------------\n"
]
}
],
"source": [
"table = 8\n",
"start = 1\n",
"max = 10\n",
"print(\"-\" * 20)\n",
"print(\"The table of 8\")\n",
"print(\"-\" * 20)\n",
"i = start\n",
"while i <= max:\n",
" result = i * table\n",
" print(i, \" * \", table, \" =\" , result)\n",
" i = i + 1\n",
"print(\"-\" * 20)\n",
"print(\"Done counting...\")\n",
"print(\"-\" * 20)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'raw_input' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-11-15156040caea>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mnumber\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mraw_input\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Enter a number between 1 - 10\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"you entered number\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumber\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'raw_input' is not defined"
]
}
],
"source": [
"number = int(raw_input(\"Enter a number between 1 - 10\"))\n",
"\n",
"print(\"you entered number\", number)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter a number between 1 - 10hello\n"
]
},
{
"ename": "ValueError",
"evalue": "invalid literal for int() with base 10: 'hello'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-12-cbf0226c6bb5>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mnumber\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Enter a number between 1 - 10\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"you entered number\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnumber\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mValueError\u001b[0m: invalid literal for int() with base 10: 'hello'"
]
}
],
"source": [
"number = int(input(\"Enter a number between 1 - 10\"))\n",
"\n",
"print(\"you entered number\", number)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter a number between 1 - 103\n",
"you entered number 3\n"
]
}
],
"source": [
"number = int(input(\"Enter a number between 1 - 10\"))\n",
"\n",
"print(\"you entered number\", number)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid character in identifier (<ipython-input-14-0905bdd47b13>, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-14-0905bdd47b13>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m file = open(“testfile.txt”,”w”)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid character in identifier\n"
]
}
],
"source": [
"file = open(“testfile.txt”,”w”) \n",
" \n",
"file.write(“Hello World”) \n",
"file.write(“This is our new text file”) \n",
"file.write(“and this is another line.”) \n",
"file.write(“Why? Because we can.”) \n",
" \n",
"file.close() "
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid character in identifier (<ipython-input-15-fb0523fc3570>, line 7)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-15-fb0523fc3570>\"\u001b[0;36m, line \u001b[0;32m7\u001b[0m\n\u001b[0;31m w.setWindowTitle(‘Guru99’)\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid character in identifier\n"
]
}
],
"source": [
"import sys\n",
"from PyQt5.QtWidgets import QApplication, QWidget\n",
"if __name__ == \"__main__\":\n",
" app = QApplication(sys.argv)\n",
" w = QWidget()\n",
" w.resize(300,300)\n",
" w.setWindowTitle(‘Guru99’)\n",
" w.show()\n",
" sys.exit(app.exec_())"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "module 'calendar' has no attribute 'SUNDAT'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-16-c97bc8b53bf7>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mcalendar\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcalendar\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTextCalendar\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcalendar\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mSUNDAT\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mstr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformatmonth\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2025\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: module 'calendar' has no attribute 'SUNDAT'"
]
}
],
"source": [
"import calendar\n",
"\n",
"c = calendar.TextCalendar(calendar.SUNDAT)\n",
"str = c.formatmonth(2025, 1)\n",
"print(str)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" January 2025\n",
"Su Mo Tu We Th Fr Sa\n",
" 1 2 3 4\n",
" 5 6 7 8 9 10 11\n",
"12 13 14 15 16 17 18\n",
"19 20 21 22 23 24 25\n",
"26 27 28 29 30 31\n",
"\n"
]
}
],
"source": [
"import calendar\n",
"\n",
"c = calendar.TextCalendar(calendar.SUNDAY)\n",
"str = c.formatmonth(2025, 1)\n",
"print(str)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['Python']\n"
]
}
],
"source": [
"import re\n",
"xx = \"Python is a Simple Programming Language\"\n",
"r1 = re.findall(r\"^\\w+\",xx)\n",
"print(r1)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['we', 'are', 'splitting', 'the', 'words']\n"
]
}
],
"source": [
"import re\n",
"print((re.split(r'\\s','we are splitting the words')))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}