Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-*-coding:utf8;-*-
- #qpy:3
- #qpy:console
- import math
- print("""Calculator programmed my ahmed
- **
- **
- **
- the Calculator can perform the following functions
- 1 four basic operations (add,multiply, subtract and divide)
- 2.Squares and Square root
- 3.mean
- 4.range
- 5.area and volume of basic shapes
- 6.factorials
- 7.trigonmetric operations (cos,sin and tan
- 8.logarithmic functions
- 9.modular arithmetic
- 10.One line maths(+ - / *)
- 10.many mor features to be added soon""")
- def calculate ():
- print("Enter 'add' to add two numbers")
- print("Enter 'subtract' to subtract two numbers")
- print("enter 'oneline' to add subtract or divide more than two numbers")
- print("Enter 'multiply' to multiply two numbers")
- print("Enter 'divide' to divide two numbers")
- print("Enter 'others' For more functions")
- print("Enter 'mod' for modular arithmetic")
- print("Enter 'quit' to end the program")
- user_input = input(": ")
- if user_input == "add":
- num1 = float(input("Enter a number: "))
- num2 = float(input("Enter another number: "))
- result = str(num1 + num2)
- print(result)
- elif user_input == "subtract":
- num1 = float(input("Enter a number: "))
- num2 = float(input("Enter another number: "))
- result = str(num1 - num2)
- print(result)
- elif user_input == "oneline":
- def oneline():
- try:
- oneline_math = eval(input("enter math expression (e.g 1+1+1, 5*4*1) "))
- print(oneline_math)
- print("do you wish to repeat for yes enter 'y' for no enter 'n' ")
- def repeat():
- repl = input("y or n:" )
- if repl == "y":
- oneline()
- elif repl =="n" :
- calculate()
- else:
- print("try again")
- repeat()
- repeat()
- except SyntaxError:
- print("syntax error please try again")
- oneline()
- except ZeroDivisionError:
- print("don't divide by zero try again")
- oneline()
- except :
- print ("error try again")
- oneline()
- oneline()
- elif user_input == "multiply":
- def multiply():
- try:
- num1 = float(input("Enter a number: "))
- num2 = float(input("Enter another number: "))
- result = str(num1 * num2)
- print(result)
- except:
- print("error try again")
- multiply()
- def repeat():
- print("do you wish to repeat for yes enter 'y' for no enter 'n' ")
- repl = input("y or n:" )
- if repl == "y":
- multiply()
- elif repl =="n" :
- calculate()
- else:
- print("try again")
- repeat()
- multiply()
- repeat()
- elif user_input == "divide":
- num1 = float(input("Enter a number: "))
- num2 = float(input("Enter another number: "))
- result = str(num1 / num2)
- print(result)
- elif user_input == "mod":
- num1 = float(input("Enter a number: "))
- num2 = float(input("Enter another number: "))
- result = str(num1 % num2)
- print(result)
- elif user_input == "quit":
- exit()
- elif user_input == "others":
- def others():
- print("waiting")
- print ("""
- for Sine type sin
- for Cosine of type cos
- for Tangeant type: tan
- for Square root type: sqrt
- for square type sq
- for log type log
- for factorials type factorial
- for mean or range type statistics
- for area of a (rectangle/square, triangle, circle) type area
- type back to go back
- type q to quit
- """)
- fcn = input(": ")
- print(fcn)
- if fcn == "sin":
- num=float(input("enter number: "))
- result = float(math.radians(num))
- print(str(math.sin(result)))
- elif fcn == "cos":
- num=float(input("enter number: "))
- result = float(math.radians(num))
- print(str(math.cos(result)))
- elif fcn == "tan":
- num=float(input("enter number: "))
- result = float(math.radians(num))
- print(str(math.tan(result)))
- elif fcn == "sqr":
- num=float(input("enter number: "))
- result = float(num) * float(num)
- another ="square of " + (str(num)) + " is " + (str(result))
- print(another)
- elif fcn == "back":
- calculate()
- elif fcn == "sqrt":
- num=float(input("enter number: "))
- result = float(math.sqrt(num))
- another ="square root of " + (str(num)) + " is " + (str(result))
- print(another)
- elif fcn == "q":
- print("bye bye")
- exit()
- elif fcn == "factorial":
- num=int(input("enter number: "))
- result = int(math.factorial(num))
- another = (str(num)) + "! " + "is " + (str(result))
- print(another)
- else:
- others()
- others()
- else:
- calculate()
- def again():
- while 1==1:
- print("any other calculations ?? enter yes or no")
- answer = input(": ")
- if answer == "yes":
- calculate()
- elif answer == "no":
- print("bye bye")
- exit()
- else:
- again()
- calculate()
- again()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement