Lab 2

Lab 2

Lab Description: This experiment help us how to solve problem which were asked to user by using if, elif, else statement. We asked user to give two integers and solve different type of problems. User were give some selections such as:

1 – Sum of two number.

2 – Subtraction of two numbers.

3 – Multiplication of two numbers.

4 – Division of two numbers.

5 – Remainder of two numbers.

6 – Whether first number is less than, equal to, or greater than second number.

This is the program:

# Viralkumar Mistry
# Lab 2 – Control flow
# Section: 9306
# Date: 02/28/2013

# Asks the user to enter two integer numbers x and y.
# The program should ask the user to select one of the following operations and display the results back:

a = 1
while a ==1:
x = input (“Enter 1st number: “)
b = float(x)
if b ==0:
print (“This is the end.”)
a = 0
else:
y = input (“Enter 2nd number: “)
c = float(y)
if c ==0:
print (“This is the end.”)
a = 0
else:
selection = 7
while selection > 6 or selection < 1:

# Ask user to select an option
print “1 – The sum x + y”
print “2 – The difference x – y”
print “3 – The product x * y”
print “4 – The quotient x / y”
print “5 – The remainder of x and y”
print “6 – Whether x is less than, equal to, or greater      than y”

selection = input (” Please select an option: “)

if selection ==1:
result = b + c
print (“The sum of x and y is: “), result
elif selection ==2:
result = b – c
print (“The difference between x and y is: “), result
elif selection ==3:
result = b * c
print (“The product of x and y is: “), result
elif selection ==4:
result = b / c
print (“The quotient of x and y is: “), result
elif selection ==5:
result = b % c
print (“The remainder of x and y is: “), result
elif selection ==6:
if b < c:
print b, (“is less than”), c
elif b == c:
print b, (“is equal to”), c
else:
print b, (“is greater than”),c
elif selection > 6 or selection < 1:
print (“Please select an option 1 through 6″)
a = input (” Do you want to continue? (Enter 1 to continue)(Enter 0 to  end program)”)
while a > 1 or a < 0:
a = input (” Do you want to continue? (Enter 1 to continue)(Enter 0 to end program)”)

Screen shot: