calculator code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
print("calculator") | |
start = time.time() | |
restart = "yes" | |
while restart == "yes" or restart == "y" or restart == "yea" or restart == "yeah": | |
first_number = int(input("whats the first number in your equation if you are finding x put any number")) | |
operator = input("are you multiplying, adding, subracting, power, find x, or dividing? ") | |
second_number = int(input("whats the second number in your equation?if you are finding x put any number ")) | |
if operator == "multiplying" or operator == "multiply" or operator == "multiplication": | |
print(first_number * second_number) | |
elif operator == "adding" or operator == "add" or operator == "+" or operator == "addition": | |
print(first_number + second_number) | |
elif operator == "subtracting" or operator == "subtract" or operator == "minus" or operator == "-" or operator == "subtraction": | |
print(first_number - second_number) | |
elif operator == "dividing" or operator == "division" or operator == "divide" or operator == "/": | |
print(first_number / second_number) | |
elif operator == "power" or operator == "^" or operator == "to the power of": | |
print(first_number ** second_number) | |
elif operator == "find x" or operator == "x" or operator == "finding x": | |
x1 = int(input("whats the amount of x on the first side of the equation? ex: 2x+3=x+4 you would put 2 as the amount for x. if there is no x on the first side of the equation put 0")) | |
num1 = int(input("whats the number on the first side of the equation? ex 2x+3=x+4 you would put 3 for the number. if there is no number on the first side of the equation put 0")) | |
x2 = int(input("whats the amount of x on the second side of the equation? ex: 2x+3=x+4 you would put 1 as the amount for x. if there is no x on the second side of the equation put 0")) | |
num2 = int(input("whats the number on the second side of the equation? ex 2x+3=x+4 you would put 4 for the number. if there is no number on the second side of the equation put 0")) | |
step1 = (x2 - x1) | |
step2 = (num2 - num1) | |
step3 = (step2 / step1) | |
step4 = (step3 * -1) | |
print("the value of x is " + str(step4)) | |
restart = input("do you want to go again?").lower() | |
if restart == "no" or restart == "nah" or restart == "nope" or restart == "n": | |
print("thanks for calculating!") | |
time2 = (time.time() - start) | |
print("you spent " + str(time2) + " seconds calculating!") | |
#"no" or restart == "nah" or restart == "nope" or restart == "n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment