Lab Description:
In this lab basically we have to re-writte (Lab 2) but this time we going to use functions.
Basically this lab 3 make the the user to type two integers numbers, and after the user type any integers numbers we ask the user to select an operation with the one that he want to work.
This is the 7 operation that the code need.
1- Sum numbers
2- Subtract numbers
3- Multiply numbers
4- Divide numbers
5- Remainder of numbers
6- Compare numbers
7- Exit
Code:
while True:
print ‘press 1 for addition’
print ‘press 2 for substraction’
print ‘press 3 for multiplication’
print ‘press 4 for division’
print ‘press 5 for reminder’
print ‘press 6 to compare two numbers’
print ‘press7 to exit’
Val = input (‘please select one option’)
if Val == 7:
print (‘Have a nice day’)
break
x1 = input (‘enter the first value’)
y1 = input (‘enter the second value’)
x = float (x1)
y = float (y1)
def add(add):
v=x+y
return v
def sub(sub):
v=x-y
return v
def mul(mul):
v=x*y
return v
def div(div):
v=x/y
return v
def rem(rem):
v=x%y
return v
if Val == 1:
print’The sum of ‘,x,’and’,y,’is equal to ‘,add(add)
elif VAl == 2:
print’The Subtraction of ‘,x,’and’,y,’is equal to ‘,sub(sub)
elif Val == 3:
print’The product of ‘,x,’and’,y,’is equal to ‘,mul(mul)
elif Val == 4:
print’The Division of ‘,x,’and’,y,’is equal to ‘,div(div)
elif Val == 5:
print’The Reminder of ‘,x,’and’,y,’is equal to ‘,rem(rem)
else:
if x>y:
print x,’ is great than ‘,y
elif x<y:
print x,’ is less than ‘,y
else:
print x,’ is equal to ‘,y
Screenshots: