Lab 3

Lab description: building a program that allow the user to do math operations like add, subtract, and multiplication using what we have learned in lab 2 “variables, data types, operators and statements and expressions.

code:

# -*- coding: cp1252 -*-
def add (x,y):
z = x+y
return z
def subtract (x,y):
z = x-y
return z
def multiply (x,y):
z = x*y
return z
def divide (x,y):
z = x/y
return z
def remainder (x,y):
z = x%y
return z
def xgy (x,y):
if (x>y):
return ( “X is greater than Y” )
elif (x<y):
return ( “X is smaller than Y”  )
elif (x == y):
return ( “x is equal to Y” )
def print_menu ():
print (“1. Addition”)
print (“2. Subtraction”)
print (“3. Multiplication”)
print (“4. Division”)
print (“5. Remainder”)
print (“6. Comparision”)
print (“7. Exit Program”)
print_menu ()
menu_item = input (“Which operation would you like to perform?”)
menu_item = int (menu_item)
while (menu_item !=7):
x = input (“What is your first value?”)
y = input (“What is your second value?”)
x = int (x)
y = int (y)
if (menu_item == 1):
z= add (x,y)
print (z)
if (menu_item == 2):
subtract (x,y)
z= subtract (x,y)
print (z)
if (menu_item == 3):
multiply (x,y)
z = multiply(x,y)
print (z)
if (menu_item == 4):
divide (x,y)
z= divide (x,y)
print (z)
if (menu_item == 5):
remainder (x,y)
z= remainder (x,y)
print (z)
if (menu_item == 6):
xgy(x,y)
z= xgy (x,y)
print (z)
print_menu ()
menu_item = input (“Which operation would you like to perform?”)
menu_item = int (menu_item)

lab3-1 lab3-2

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

A City Tech OpenLab ePortfolio