Advertisement
Guest User

Untitled

a guest
May 26th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "# <center>Sean Dunn Lab Three</center>"
  8. ]
  9. },
  10. {
  11. "cell_type": "markdown",
  12. "metadata": {},
  13. "source": [
  14. "Sean_Dunn_Lab_Problem_3.py<br>\n",
  15. "Date Created: 5/13/2019 <br>\n",
  16. "Created by: Sean Dunn, IST 652, Wed to 7pm<br>\n",
  17. "Purpose: Activity to better understand Python coding<br>\n",
  18. "Title: Lab Problem 3"
  19. ]
  20. },
  21. {
  22. "cell_type": "markdown",
  23. "metadata": {},
  24. "source": [
  25. "## <font color=\"blue\"> Problem 1. What will the following Python program print out?</font>"
  26. ]
  27. },
  28. {
  29. "cell_type": "code",
  30. "execution_count": 1,
  31. "metadata": {},
  32. "outputs": [],
  33. "source": [
  34. "def fred(): \n",
  35. " print(\"Zapped\") "
  36. ]
  37. },
  38. {
  39. "cell_type": "code",
  40. "execution_count": 2,
  41. "metadata": {},
  42. "outputs": [],
  43. "source": [
  44. "def jane(): \n",
  45. " print(\"ABCdef\")"
  46. ]
  47. },
  48. {
  49. "cell_type": "markdown",
  50. "metadata": {},
  51. "source": [
  52. "jane()<br>\n",
  53. "fred()<br>\n",
  54. "jane()<br>\n",
  55. "\n",
  56. "I would presume the output would be:\n",
  57. "\n",
  58. "ABCdef<br>\n",
  59. "Zapped<br>\n",
  60. "ABCdef<br>"
  61. ]
  62. },
  63. {
  64. "cell_type": "markdown",
  65. "metadata": {},
  66. "source": [
  67. "### Therefore, the answer would be d) ABCdef Zapped ABCdef"
  68. ]
  69. },
  70. {
  71. "cell_type": "markdown",
  72. "metadata": {},
  73. "source": [
  74. "### For confirmation"
  75. ]
  76. },
  77. {
  78. "cell_type": "code",
  79. "execution_count": 3,
  80. "metadata": {},
  81. "outputs": [
  82. {
  83. "name": "stdout",
  84. "output_type": "stream",
  85. "text": [
  86. "ABCdef\n",
  87. "Zapped\n",
  88. "ABCdef\n"
  89. ]
  90. }
  91. ],
  92. "source": [
  93. "jane()\n",
  94. "fred()\n",
  95. "jane()"
  96. ]
  97. },
  98. {
  99. "cell_type": "markdown",
  100. "metadata": {},
  101. "source": [
  102. "↑↑↑ demonstrates that the answer was correct "
  103. ]
  104. },
  105. {
  106. "cell_type": "markdown",
  107. "metadata": {},
  108. "source": [
  109. "## <font color=\"blue\">A) Problem 2. Rewrite your pay computation with time-and-a-half for overtime and create a function called computepay that takes two parameters (hours and rate) and returns Gross pay. Make sure to display your results with the label of Gross pay:. Call the function 3 or 4 times and enter different values (at least one with over 40 hours).</blue>"
  110. ]
  111. },
  112. {
  113. "cell_type": "markdown",
  114. "metadata": {},
  115. "source": [
  116. "* Enter Hours: 45 \n",
  117. "* Enter Rate: 10 \n",
  118. "* Gross Pay: 475.0 "
  119. ]
  120. },
  121. {
  122. "cell_type": "code",
  123. "execution_count": 4,
  124. "metadata": {},
  125. "outputs": [
  126. {
  127. "name": "stdout",
  128. "output_type": "stream",
  129. "text": [
  130. "Enter hours: 45\n",
  131. "Enter rate: 10\n",
  132. "Gross Pay: $475.00\n"
  133. ]
  134. }
  135. ],
  136. "source": [
  137. "# This program will gather the hours and rate from a user and returns Gross pay\n",
  138. "hours=input('Enter hours: ')\n",
  139. "rate=input('Enter rate: ')\n",
  140. "# define the function computepay\n",
  141. "def computepay():\n",
  142. " regular_hours = 40\n",
  143. " ot_hours = int(hours) - 40\n",
  144. " regular_pay = 40 * float(rate)\n",
  145. " ot_pay = int(ot_hours) * float(rate) * 1.5\n",
  146. " gross_pay = regular_pay + ot_pay\n",
  147. " print('Gross Pay: ${:.2f}'.format(gross_pay))\n",
  148. "computepay()"
  149. ]
  150. },
  151. {
  152. "cell_type": "markdown",
  153. "metadata": {},
  154. "source": [
  155. "An alternative way to have inputs as arguments\n",
  156. "↓↓↓ "
  157. ]
  158. },
  159. {
  160. "cell_type": "code",
  161. "execution_count": 5,
  162. "metadata": {},
  163. "outputs": [
  164. {
  165. "name": "stdout",
  166. "output_type": "stream",
  167. "text": [
  168. "Gross Pay: $825.00\n"
  169. ]
  170. }
  171. ],
  172. "source": [
  173. "def computepay(hours,rate):\n",
  174. " regular_hours = 40\n",
  175. " ot_hours = int(hours) - 40\n",
  176. " regular_pay = 40 * float(rate)\n",
  177. " ot_pay=int(ot_hours) * float(rate) * 1.5\n",
  178. " gross_pay = regular_pay + ot_pay\n",
  179. " print('Gross Pay: ${:.2f}'.format(gross_pay))\n",
  180. "computepay(50,15)"
  181. ]
  182. },
  183. {
  184. "cell_type": "code",
  185. "execution_count": 6,
  186. "metadata": {},
  187. "outputs": [
  188. {
  189. "name": "stdout",
  190. "output_type": "stream",
  191. "text": [
  192. "Gross Pay: $4200.00\n"
  193. ]
  194. }
  195. ],
  196. "source": [
  197. "computepay(60,60)"
  198. ]
  199. },
  200. {
  201. "cell_type": "code",
  202. "execution_count": 7,
  203. "metadata": {},
  204. "outputs": [
  205. {
  206. "name": "stdout",
  207. "output_type": "stream",
  208. "text": [
  209. "Gross Pay: $1375.00\n"
  210. ]
  211. }
  212. ],
  213. "source": [
  214. "computepay(50,25)"
  215. ]
  216. }
  217. ],
  218. "metadata": {
  219. "kernelspec": {
  220. "display_name": "Python 3",
  221. "language": "python",
  222. "name": "python3"
  223. },
  224. "language_info": {
  225. "codemirror_mode": {
  226. "name": "ipython",
  227. "version": 3
  228. },
  229. "file_extension": ".py",
  230. "mimetype": "text/x-python",
  231. "name": "python",
  232. "nbconvert_exporter": "python",
  233. "pygments_lexer": "ipython3",
  234. "version": "3.7.1"
  235. }
  236. },
  237. "nbformat": 4,
  238. "nbformat_minor": 2
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement