Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# <center>Sean Dunn Lab Three</center>"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Sean_Dunn_Lab_Problem_3.py<br>\n",
- "Date Created: 5/13/2019 <br>\n",
- "Created by: Sean Dunn, IST 652, Wed to 7pm<br>\n",
- "Purpose: Activity to better understand Python coding<br>\n",
- "Title: Lab Problem 3"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## <font color=\"blue\"> Problem 1. What will the following Python program print out?</font>"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "def fred(): \n",
- " print(\"Zapped\") "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [],
- "source": [
- "def jane(): \n",
- " print(\"ABCdef\")"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "jane()<br>\n",
- "fred()<br>\n",
- "jane()<br>\n",
- "\n",
- "I would presume the output would be:\n",
- "\n",
- "ABCdef<br>\n",
- "Zapped<br>\n",
- "ABCdef<br>"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Therefore, the answer would be d) ABCdef Zapped ABCdef"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### For confirmation"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "ABCdef\n",
- "Zapped\n",
- "ABCdef\n"
- ]
- }
- ],
- "source": [
- "jane()\n",
- "fred()\n",
- "jane()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "↑↑↑ demonstrates that the answer was correct "
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## <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>"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "* Enter Hours: 45 \n",
- "* Enter Rate: 10 \n",
- "* Gross Pay: 475.0 "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Enter hours: 45\n",
- "Enter rate: 10\n",
- "Gross Pay: $475.00\n"
- ]
- }
- ],
- "source": [
- "# This program will gather the hours and rate from a user and returns Gross pay\n",
- "hours=input('Enter hours: ')\n",
- "rate=input('Enter rate: ')\n",
- "# define the function computepay\n",
- "def computepay():\n",
- " regular_hours = 40\n",
- " ot_hours = int(hours) - 40\n",
- " regular_pay = 40 * float(rate)\n",
- " ot_pay = int(ot_hours) * float(rate) * 1.5\n",
- " gross_pay = regular_pay + ot_pay\n",
- " print('Gross Pay: ${:.2f}'.format(gross_pay))\n",
- "computepay()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "An alternative way to have inputs as arguments\n",
- "↓↓↓ "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Gross Pay: $825.00\n"
- ]
- }
- ],
- "source": [
- "def computepay(hours,rate):\n",
- " regular_hours = 40\n",
- " ot_hours = int(hours) - 40\n",
- " regular_pay = 40 * float(rate)\n",
- " ot_pay=int(ot_hours) * float(rate) * 1.5\n",
- " gross_pay = regular_pay + ot_pay\n",
- " print('Gross Pay: ${:.2f}'.format(gross_pay))\n",
- "computepay(50,15)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Gross Pay: $4200.00\n"
- ]
- }
- ],
- "source": [
- "computepay(60,60)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Gross Pay: $1375.00\n"
- ]
- }
- ],
- "source": [
- "computepay(50,25)"
- ]
- }
- ],
- "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.7.1"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement