Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [
  8. {
  9. "name": "stdout",
  10. "output_type": "stream",
  11. "text": [
  12. "l1 is greater than l2\n",
  13. "1\n",
  14. "l1 is lesser than l2\n",
  15. "2\n",
  16. "l1 is lesser than l2\n",
  17. "3\n"
  18. ]
  19. }
  20. ],
  21. "source": [
  22. "l1=[1,2,3]\n",
  23. "l2=[3,2,1]\n",
  24. "n=0\n",
  25. "while(n<3):\n",
  26. " if(l1[n]<l2[n]):\n",
  27. " print(\"l1 is greater than l2\")\n",
  28. " else:\n",
  29. " print(\"l1 is lesser than l2\")\n",
  30. " n=n+1\n",
  31. " print(n)"
  32. ]
  33. },
  34. {
  35. "cell_type": "code",
  36. "execution_count": 2,
  37. "metadata": {},
  38. "outputs": [
  39. {
  40. "name": "stdout",
  41. "output_type": "stream",
  42. "text": [
  43. "0\n",
  44. "l1 is lesser than l2\n",
  45. "1\n",
  46. "l1 is lesser than l2\n",
  47. "2\n",
  48. "l1 is lesser than l2\n",
  49. "3\n",
  50. "l1 is greater than l2\n",
  51. "4\n",
  52. "l1 is greater than l2\n",
  53. "5\n",
  54. "l1 is greater than l2\n"
  55. ]
  56. }
  57. ],
  58. "source": [
  59. "l1=[1,2,3,4,5,6]\n",
  60. "l2=[6,5,4,3,2,1]\n",
  61. "n=0\n",
  62. "while(n<6):\n",
  63. " print(n)\n",
  64. " if(l1[n]>l2[n]):\n",
  65. " print(\"l1 is greater than l2\")\n",
  66. " else:\n",
  67. " print(\"l1 is lesser than l2\")\n",
  68. " n=n+1"
  69. ]
  70. },
  71. {
  72. "cell_type": "code",
  73. "execution_count": 3,
  74. "metadata": {},
  75. "outputs": [
  76. {
  77. "name": "stdout",
  78. "output_type": "stream",
  79. "text": [
  80. "Given number is odd: 13\n",
  81. "Given number is even: 10\n"
  82. ]
  83. }
  84. ],
  85. "source": [
  86. "def check_odd_even(b):\n",
  87. " odd_even = b%2\n",
  88. " if(odd_even != 0):\n",
  89. " print(\"Given number is odd: \",b)\n",
  90. " else:\n",
  91. " print(\"Given number is even: \",b)\n",
  92. " \n",
  93. " \n",
  94. "check_odd_even(13)\n",
  95. "check_odd_even(10)"
  96. ]
  97. },
  98. {
  99. "cell_type": "code",
  100. "execution_count": 4,
  101. "metadata": {},
  102. "outputs": [
  103. {
  104. "name": "stdout",
  105. "output_type": "stream",
  106. "text": [
  107. "15\n",
  108. "25\n",
  109. "35\n",
  110. "45\n",
  111. "55\n"
  112. ]
  113. }
  114. ],
  115. "source": [
  116. "tuple=(10,20,30,40,50)\n",
  117. "n=0\n",
  118. "while(n<5):\n",
  119. " a=tuple[n]\n",
  120. " a+=5\n",
  121. " print(a)\n",
  122. " n+=1"
  123. ]
  124. },
  125. {
  126. "cell_type": "code",
  127. "execution_count": 5,
  128. "metadata": {},
  129. "outputs": [
  130. {
  131. "name": "stdout",
  132. "output_type": "stream",
  133. "text": [
  134. "['orange']\n",
  135. "['orange', 'orange']\n"
  136. ]
  137. }
  138. ],
  139. "source": [
  140. "squares = ['orange', 'orange', 'purple', 'blue ', 'orange']\n",
  141. "new_squares = []\n",
  142. "i=0\n",
  143. "while(squares[i]==\"orange\"):\n",
  144. " new_squares.append(squares[i])\n",
  145. " print(new_squares)\n",
  146. " i+=1"
  147. ]
  148. },
  149. {
  150. "cell_type": "code",
  151. "execution_count": 6,
  152. "metadata": {},
  153. "outputs": [
  154. {
  155. "name": "stdout",
  156. "output_type": "stream",
  157. "text": [
  158. "['orange', 'orange']\n"
  159. ]
  160. }
  161. ],
  162. "source": [
  163. "squares = ['orange', 'orange', 'purple', 'blue ', 'orange']\n",
  164. "new_squares = []\n",
  165. "i=0\n",
  166. "while(squares[i]==\"orange\"):\n",
  167. " new_squares.append(squares[i])\n",
  168. " i+=1\n",
  169. "print(new_squares)"
  170. ]
  171. },
  172. {
  173. "cell_type": "code",
  174. "execution_count": 8,
  175. "metadata": {},
  176. "outputs": [
  177. {
  178. "name": "stdout",
  179. "output_type": "stream",
  180. "text": [
  181. "['orange', 'orange', 'purple', 'blue ', 'orange']\n"
  182. ]
  183. }
  184. ],
  185. "source": [
  186. "squares = ['orange', 'orange', 'purple', 'blue ', 'orange']\n",
  187. "new_squares = []\n",
  188. "elements=len(squares)\n",
  189. "for i in range(elements):\n",
  190. " new_squares.append(squares[i])\n",
  191. " i+=1\n",
  192. "print(new_squares)"
  193. ]
  194. }
  195. ],
  196. "metadata": {
  197. "kernelspec": {
  198. "display_name": "Python",
  199. "language": "python",
  200. "name": "conda-env-python-py"
  201. },
  202. "language_info": {
  203. "codemirror_mode": {
  204. "name": "ipython",
  205. "version": 3
  206. },
  207. "file_extension": ".py",
  208. "mimetype": "text/x-python",
  209. "name": "python",
  210. "nbconvert_exporter": "python",
  211. "pygments_lexer": "ipython3",
  212. "version": "3.6.7"
  213. }
  214. },
  215. "nbformat": 4,
  216. "nbformat_minor": 4
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement