You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""The previous script becomes very boring for the user as he has to keep on typing just numbers and of wants to interact using
simple english language he is unable to do so. Also the program terminates after one execution and if the user wants to keep on
performing operations it becomes difficult.
I have tried making a more simple and interactive calculator which allows the user to input any statement for performing the tasks. """
defCalculator(num_1,num_2):
#Executing the loop infinite times as we donot know how many times the user will want to run
while(True):
choice=input("Enter what you want to perform: ")
print()
#For Addition user can type any Sentence containing word related to it and will get the output but here we are checking only for the common words
if ("addition"inchoice) or ("add"inchoice) or ("sum"inchoice) or ("plus"inchoice):
sum= (num_1) + (num_2)
print("Output....")
print("Adding {} and {} results to {}".format(num_1,num_2,sum))
print()
#For Subtraction user can type any Sentence containing word related to it and will get the output but here we are checking only for the common words
elif ("subtraction"inchoice) or ("minus"inchoice) or ("difference"inchoice) or ("subtract"inchoice):
if( num_1>num_2 ):
diff= (num_1) - (num_2)
print("Output....")
print("Subtracting {} from {} results to {}".format(num_2,num_1,diff))
print()
elif( num_2>num_1 ):
diff= (num_2) - (num_1)
print("Output....")
print("Subtracting {} from {} results to {}".format(num_1,num_2,diff))
print()
#For Multiplication user can type any Sentence cpntaining word related to it and will get the output but here we are checking only for the common words
elif ("multiplication"inchoice) or ("product"inchoice) or ("multiply"inchoice):
if(num_1==0ornum_2==0):
print("Output....")
print("Multiplying {} and {} results to 0".format(num_1,num_2))
print()
elif(num_1==1):
print("Output....")
print("Multiplying {} and {} results to {}".format(num_1,num_2,num_2))
print()
elif(num_2==1):
print("Output....")
print("Multiplying {} and {} results to {}".format(num_1,num_2,num_1))
print()
else:
mul= (num_1) * (num_2)
print("Output....")
print("Multiplying {} and {} results to {}".format(num_1,num_2,mul))
print()
#For Division user can type any Sentence cpntaining word related to it and will get the output but here we are checking only for the common words
elif("division"inchoice) or ("divide"inchoice) or ("quotient"inchoice):
if( num_1>num_2 ):
if(num_2==0):
print("Output....")
print("Error: Please try with some other values!")
elif(num_1==0):
print("Output....")
print("Dividing {} from {} results to 0".format(num_1,num_2))
print()
else:
div= (num_1) / (num_2)
print("Output....")
print("Dividing {} from {} results to {}".format(num_1,num_2,div))
print()
elif(num_1==0andnum_2==0):
print("Infinity!")
print()
elif( num_2>num_1 ):
if(num_1==0):
print("Output....")
print("Error: Please try with some other values!")
print()
elif(num_2==0):
print("Output....")
print("Dividing {} from {} results to 0".format(num_1,num_2))
print()
else:
div= (num_2) / (num_1)
print("Output....")
print("Dividing {} from {} results to {}".format(num_2,num_1,div))
print()
#For exiting the loop user can type any Sentence containing word related to it and it will exit from the loop but here we are checking for the common words
elif ("exit"inchoice) or ("stop"inchoice) or ("return"inchoice):
break
else:
print()
print("Operation not found: Please try again!")
print()
defmain():
print()
print(" THIS IS A BASIC USER FRIENDLY CALCULATOR! ")