top of page

Python | Making a Calculator only use if or else statement

Updated: Aug 26, 2021



#Program By eboostup.com
num1=float(input( "First Number = "))
num2=float(input( "Second Number = "))
Operator=str( input("Enter The Value (+,-,*,/) = "))
decimal=input('''Do You Want The Answer In Decimal? Say "Yes= Y Or No= N " = ''')
if decimal=="Y":
   if Operator=="+":
      print(num1,Operator,num2," = ",float(num1+num2))
   if Operator=="-":
      print(num1,Operator,num2," = ",float(num1-num2))
   if Operator=="*":
      print(num1,Operator,num2," = ",float(num1*num2))
   if Operator=="/":
      print(num1,Operator,num2," = ",float(num1/num2))
else:
       print('''You are entered invalid value''')

if decimal=="N":
   if Operator=="+":
      print(num1,Operator,num2," = ",int(num1+num2))
   if Operator=="-":
      print(num1,Operator,num2," = ",int(num1-num2))
   if Operator=="*":
      print(num1,Operator,num2," = ",int(num1*num2))
   if Operator=="/":
      print(num1,Operator,num2," = ",int(num1/num2))
else:
       print('''  Please try again  ''')
print("Powered by 
  eboostup")
#ankushdhingra

Comentarios

Obtuvo 0 de 5 estrellas.
Aún no hay calificaciones

Agrega una calificación
bottom of page