Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "<h1>Conditions in Phyton</h1>"
  8. ]
  9. },
  10. {
  11. "cell_type": "markdown",
  12. "metadata": {},
  13. "source": [
  14. "<h2>Comparisons Operator</h2>"
  15. ]
  16. },
  17. {
  18. "cell_type": "code",
  19. "execution_count": null,
  20. "metadata": {
  21. "collapsed": false,
  22. "jupyter": {
  23. "outputs_hidden": false
  24. }
  25. },
  26. "outputs": [],
  27. "source": [
  28. "# Condition Equal\n",
  29. "\n",
  30. "a = True\n",
  31. "a == False"
  32. ]
  33. },
  34. {
  35. "cell_type": "code",
  36. "execution_count": null,
  37. "metadata": {
  38. "collapsed": false,
  39. "jupyter": {
  40. "outputs_hidden": false
  41. }
  42. },
  43. "outputs": [],
  44. "source": [
  45. "# Greater than Sign\n",
  46. "\n",
  47. "i = 6\n",
  48. "i > 5"
  49. ]
  50. },
  51. {
  52. "cell_type": "code",
  53. "execution_count": null,
  54. "metadata": {
  55. "collapsed": false,
  56. "jupyter": {
  57. "outputs_hidden": false
  58. }
  59. },
  60. "outputs": [],
  61. "source": [
  62. "# Inequality Sign\n",
  63. "\n",
  64. "i = 'Circle'\n",
  65. "i != 'Rectangle'"
  66. ]
  67. },
  68. {
  69. "cell_type": "code",
  70. "execution_count": null,
  71. "metadata": {
  72. "collapsed": false,
  73. "jupyter": {
  74. "outputs_hidden": false
  75. }
  76. },
  77. "outputs": [],
  78. "source": [
  79. "# Compare characters\n",
  80. "# Note the ASCII code for A is 101 and B is 102\n",
  81. "\n",
  82. "'B' > 'A'"
  83. ]
  84. },
  85. {
  86. "cell_type": "code",
  87. "execution_count": null,
  88. "metadata": {},
  89. "outputs": [],
  90. "source": [
  91. "# Comparisons of Characters: upper case letters have different ASCII code than lower case letters\n",
  92. "\n",
  93. "'ab'>'AB'"
  94. ]
  95. },
  96. {
  97. "cell_type": "markdown",
  98. "metadata": {},
  99. "source": [
  100. "<h2>Branching</h2>"
  101. ]
  102. },
  103. {
  104. "cell_type": "code",
  105. "execution_count": null,
  106. "metadata": {
  107. "collapsed": false,
  108. "jupyter": {
  109. "outputs_hidden": false
  110. }
  111. },
  112. "outputs": [],
  113. "source": [
  114. "# If statement example\n",
  115. "\n",
  116. "age = 19\n",
  117. "#age = 18\n",
  118. "\n",
  119. "#expression that can be true or false\n",
  120. "if age > 18:\n",
  121. " \n",
  122. " #within an indent, we have the expression that is run if the condition is true\n",
  123. " print(\"you can enter\" )\n",
  124. "\n",
  125. "#The statements after the if statement will run regardless if the condition is true or false \n",
  126. "print(\"move on\")"
  127. ]
  128. },
  129. {
  130. "cell_type": "code",
  131. "execution_count": null,
  132. "metadata": {
  133. "collapsed": false,
  134. "jupyter": {
  135. "outputs_hidden": false
  136. }
  137. },
  138. "outputs": [],
  139. "source": [
  140. "# Else statement example\n",
  141. "\n",
  142. "age = 18\n",
  143. "# age = 19\n",
  144. "\n",
  145. "if age > 18:\n",
  146. " print(\"you can enter\" )\n",
  147. "else:\n",
  148. " print(\"go see Meat Loaf\" )\n",
  149. " \n",
  150. "print(\"move on\")"
  151. ]
  152. },
  153. {
  154. "cell_type": "code",
  155. "execution_count": null,
  156. "metadata": {
  157. "collapsed": false,
  158. "jupyter": {
  159. "outputs_hidden": false
  160. }
  161. },
  162. "outputs": [],
  163. "source": [
  164. "# Elif statment example\n",
  165. "\n",
  166. "age = 17\n",
  167. "\n",
  168. "if age > 18:\n",
  169. " print(\"you can enter\" )\n",
  170. "elif age == 18:\n",
  171. " print(\"go see Pink Floyd\")\n",
  172. "else:\n",
  173. " print(\"go see Meat Loaf\" )\n",
  174. " \n",
  175. "print(\"move on\")"
  176. ]
  177. },
  178. {
  179. "cell_type": "code",
  180. "execution_count": null,
  181. "metadata": {
  182. "collapsed": false,
  183. "jupyter": {
  184. "outputs_hidden": false
  185. }
  186. },
  187. "outputs": [],
  188. "source": [
  189. "# Condition statement example\n",
  190. "\n",
  191. "#album_year = 1983\n",
  192. "album_year = 1970\n",
  193. "\n",
  194. "if album_year > 1980:\n",
  195. " print(\"Album year is greater than 1980\")\n",
  196. "else:\n",
  197. " print(\"less than 1980\")\n",
  198. "\n",
  199. "print('do something..')"
  200. ]
  201. },
  202. {
  203. "cell_type": "markdown",
  204. "metadata": {},
  205. "source": [
  206. "<h2>Logical Operators</h2>"
  207. ]
  208. },
  209. {
  210. "cell_type": "code",
  211. "execution_count": null,
  212. "metadata": {
  213. "collapsed": false,
  214. "jupyter": {
  215. "outputs_hidden": false
  216. }
  217. },
  218. "outputs": [],
  219. "source": [
  220. "# Condition statement example\n",
  221. "\n",
  222. "album_year = 1980\n",
  223. "\n",
  224. "if(album_year > 1979) and (album_year < 1990):\n",
  225. " print (\"Album year was in between 1980 and 1989\")\n",
  226. " \n",
  227. "print(\"\")\n",
  228. "print(\"Do Stuff..\")"
  229. ]
  230. },
  231. {
  232. "cell_type": "code",
  233. "execution_count": null,
  234. "metadata": {},
  235. "outputs": [],
  236. "source": []
  237. }
  238. ],
  239. "metadata": {
  240. "kernelspec": {
  241. "display_name": "Python 3",
  242. "language": "python",
  243. "name": "python3"
  244. },
  245. "language_info": {
  246. "codemirror_mode": {
  247. "name": "ipython",
  248. "version": 3
  249. },
  250. "file_extension": ".py",
  251. "mimetype": "text/x-python",
  252. "name": "python",
  253. "nbconvert_exporter": "python",
  254. "pygments_lexer": "ipython3",
  255. "version": "3.6.7"
  256. }
  257. },
  258. "nbformat": 4,
  259. "nbformat_minor": 4
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement