Lab 2

Lab Description:

In this example of programming we use a  a function. It is a named sequence of statements that performs a computation. When you define a function, you specify the name and the sequence of statements.

Code:

x = int(input(‘Enter the 1st number: ‘))

y = int(input(‘Enter the 2nd number: ‘))

print (‘Enter 1 to add the numbers’)

print (‘Enter 2 to subtract the numbers’)

print (‘Enter 3 to multiply the numbers’)

print (‘Enter 4 to divide the numbers’)

print (‘Enter 5 to find the remainder of x%y’)

print (‘Enter 6 for x<=y’)

z = int(input(‘Enter your selection: ‘))

if z==1:

result = x+y

print (‘The sum of ‘,x,’ and ‘,y,’ is: ‘,result)

elif z==2:

result = x-y

print (‘The difference of ‘,x,’ and ‘,y,’ is: ‘,result)

elif z==3:

result = x*y

print (‘The product of ‘,x,’ and ‘,y,’ is: ‘,result)

elif z==4:

result = x/y

print (‘The quotient of ‘,x,’ and ‘,y,’ is: ‘,result)

elif z==5:

result = x%y

print (‘The remainder of ‘,x,’ and ‘,y,’ is: ‘,result)

elif z==6:

result = x<=y

print (‘The number of ‘,x,’ is less than, ‘,y,’ is: ‘,result)

print (‘The number of ‘,x,’ is greater than, ‘,y,’ is: ‘,result)

print (‘The number of ‘,x,’ is equal to,’,y,’ is: ‘,result)

Screenshots: