{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "

Employee Pay Computation Program

" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Pay Computation Program\n", "Enter Work Hours: 45\n", "Enter Pay Rate: 10\n", "Your Payment: 475.0\n" ] } ], "source": [ "fixed_hours = 40.0\n", "work_hours = float(input('Enter Work Hours: '))\n", "pay_rate = float(input('Enter Pay Rate: '))\n", "pay = 0.0\n", "if(work_hours > fixed_hours):\n", " pay = (fixed_hours * pay_rate) + ((work_hours - fixed_hours) * (pay_rate * 1.5))\n", "else:\n", " pay = work_hours * pay_rate\n", " \n", "print('Your Payment: ' + str(pay))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

+try and except - non numerical input

" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Enter Work Hours: forty\n", "Error, please enter numeric input\n" ] } ], "source": [ "import sys\n", "\n", "fixed_hours = 40.0\n", "\n", "try:\n", " work_hours = float(input('Enter Work Hours: '))\n", " pay_rate = float(input('Enter Pay Rate: '))\n", " pay = 0.0\n", "\n", " if(work_hours > fixed_hours):\n", " pay = (fixed_hours * pay_rate) + ((work_hours - fixed_hours) * (pay_rate * 1.5))\n", " else:\n", " pay = work_hours * pay_rate\n", " \n", " print('Your Payment: ' + str(pay)) \n", " \n", "except ValueError:\n", " print('Error, please enter numeric input')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Grading Program

" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Enter Score: 0.95\n", "A\n", "\n", "Enter Score: perfect\n", "Bad score\n", "\n", "Enter Score: 10.0\n", "Bad score\n", "\n", "Enter Score: 0.78\n", "C\n", "\n", "Enter Score: 0.5\n", "F\n" ] } ], "source": [ "print(\"Score\\tGrade\")\n", "SCORES = ['>= 0.9', '>= 0.8', '>= 0.7', '>= 0.6', ' < 0.6']\n", "GRADES = ['A', 'B', 'C', 'D', 'E']\n", "for sc, gd in zip(SCORES, GRADES):\n", " print(\"%s\\t%s\" %(sc, gd))\n", "\n", "for i in range(5):\n", " try:\n", " score = float(input('Enter Score: '))\n", " if(score < 0.0 or score > 1.0):\n", " print('Bad score\\n')\n", " continue\n", " if(score >= 0.9):\n", " print('A\\n')\n", " elif(score >= 0.8):\n", " print('B\\n')\n", " elif(score >= 0.7):\n", " print('C\\n')\n", " elif(score >= 0.6):\n", " print('D\\n')\n", " else:\n", " print('F')\n", " except ValueError:\n", " print('Bad score\\n')" ] } ], "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }