Showing posts with label Nested if else. Show all posts
Showing posts with label Nested if else. Show all posts

Simple calculator using if elseif else and nested if else

a=int(raw_input('Enter the value of a:'))
b=int(raw_input('Enter the value of b:'))
print ' 1. add  2.sub  3.mul  4. div  5.exp'
n=int(raw_input('Enter the choice:'))
if n==1:
      c=a+b
      print 'Added value is:',c
elif n==2:
      if a>b:     #Nested if else
            c=a-b
            print 'Subtracted value is:',c
      else:
            c=b-a
            print 'Subtracted value is:',c
elif n==3:
      c=a*b
      print 'Multiplication value is:',c
elif n==4:
      if b==0:          #Nested if else
            print 'Division by zero not defined'
      else:
            c=float(a)/b
            print 'Divison value is:',c
elif n==5:
      c=a**b
      print 'Exponent value is:',c
else:
      print 'Invalid options'