Guest User

Untitled

a guest
Jan 17th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 2,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "# число делится и на 3 и 5\n",
  10. "def summ(N):\n",
  11. " summ = 0\n",
  12. " i = 1\n",
  13. " for i in range(N+1):\n",
  14. " if i % 15 == 0 :\n",
  15. " summ = i + summ\n",
  16. " return summ\n"
  17. ]
  18. },
  19. {
  20. "cell_type": "code",
  21. "execution_count": 3,
  22. "metadata": {},
  23. "outputs": [
  24. {
  25. "name": "stdout",
  26. "output_type": "stream",
  27. "text": [
  28. "45\n"
  29. ]
  30. }
  31. ],
  32. "source": [
  33. "print(summ(35))\n"
  34. ]
  35. },
  36. {
  37. "cell_type": "code",
  38. "execution_count": 5,
  39. "metadata": {},
  40. "outputs": [
  41. {
  42. "name": "stdout",
  43. "output_type": "stream",
  44. "text": [
  45. "33165\n"
  46. ]
  47. }
  48. ],
  49. "source": [
  50. "print(summ(1000))"
  51. ]
  52. },
  53. {
  54. "cell_type": "code",
  55. "execution_count": 6,
  56. "metadata": {},
  57. "outputs": [],
  58. "source": [
  59. "#Solve a quadratic equation, x**2 + bx + c = 0.\n",
  60. "def solve_quad(b, c):\n",
  61. " D = (b ** 2 - 4 * c)\n",
  62. " x1 = (-b + D ** 0.5) / 2\n",
  63. " x2 = (-b - D ** 0.5) / 2\n",
  64. " return x1, x2\n"
  65. ]
  66. },
  67. {
  68. "cell_type": "code",
  69. "execution_count": 7,
  70. "metadata": {},
  71. "outputs": [
  72. {
  73. "name": "stdout",
  74. "output_type": "stream",
  75. "text": [
  76. "for b=4, c=3: (-1.0, -3.0)\n"
  77. ]
  78. }
  79. ],
  80. "source": [
  81. "print(\"for b=4, c=3:\", solve_quad(4, 3))\n"
  82. ]
  83. },
  84. {
  85. "cell_type": "code",
  86. "execution_count": 8,
  87. "metadata": {},
  88. "outputs": [
  89. {
  90. "name": "stdout",
  91. "output_type": "stream",
  92. "text": [
  93. "for b=2, c=1: (-1.0, -1.0)\n"
  94. ]
  95. }
  96. ],
  97. "source": [
  98. "print(\"for b=2, c=1:\", solve_quad(2, 1))\n"
  99. ]
  100. },
  101. {
  102. "cell_type": "code",
  103. "execution_count": 9,
  104. "metadata": {},
  105. "outputs": [
  106. {
  107. "name": "stdout",
  108. "output_type": "stream",
  109. "text": [
  110. "for b=0.5, c=4: ((-0.2499999999999999+1.984313483298443j), (-0.2500000000000001-1.984313483298443j))\n"
  111. ]
  112. }
  113. ],
  114. "source": [
  115. "print(\"for b=0.5, c=4:\", solve_quad(0.5, 4))\n"
  116. ]
  117. },
  118. {
  119. "cell_type": "code",
  120. "execution_count": 10,
  121. "metadata": {},
  122. "outputs": [
  123. {
  124. "name": "stdout",
  125. "output_type": "stream",
  126. "text": [
  127. "for b=1e10, c=3: (0.0, -10000000000.0)\n"
  128. ]
  129. }
  130. ],
  131. "source": [
  132. "print(\"for b=1e10, c=3:\", solve_quad(1e10, 3))\n"
  133. ]
  134. },
  135. {
  136. "cell_type": "code",
  137. "execution_count": 11,
  138. "metadata": {},
  139. "outputs": [
  140. {
  141. "name": "stdout",
  142. "output_type": "stream",
  143. "text": [
  144. "for b=-1e10, c=3: (10000000000.0, 0.0)\n"
  145. ]
  146. }
  147. ],
  148. "source": [
  149. "print(\"for b=-1e10, c=3:\", solve_quad(-1e10, 4))"
  150. ]
  151. },
  152. {
  153. "cell_type": "code",
  154. "execution_count": null,
  155. "metadata": {},
  156. "outputs": [],
  157. "source": []
  158. }
  159. ],
  160. "metadata": {
  161. "kernelspec": {
  162. "display_name": "Python 3",
  163. "language": "python",
  164. "name": "python3"
  165. },
  166. "language_info": {
  167. "codemirror_mode": {
  168. "name": "ipython",
  169. "version": 3
  170. },
  171. "file_extension": ".py",
  172. "mimetype": "text/x-python",
  173. "name": "python",
  174. "nbconvert_exporter": "python",
  175. "pygments_lexer": "ipython3",
  176. "version": "3.6.7"
  177. }
  178. },
  179. "nbformat": 4,
  180. "nbformat_minor": 2
  181. }
Add Comment
Please, Sign In to add comment