So I know my code isn't close to efficient but it works so don't say something on that.
I'm trying to make a calculator.
I'm trying to let it run the legend if the users types j, otherwise when the user does not want too see the legend it just runs the calculator. Why is it always showing the legend? I"ve tried alot but I just can't get it to work. thanks in advance.
import math
loop = True
while loop == True:
q = input(str("Wil je de bewerkingsteken legende zien? (j/n): "))
if q == "J" or "j" :
print ("\nplus = + ")
print ("min = -")
print ("maal = X")
print ("delen door = :")
print ("quadrateren = Q")
print ("tot de kracht van = P")
print ("Worteltrekken = W")
print ("Procent = %")
num1 = float(input("\n Nummer 1: "))
bew = input("\n Bewerkingsteken: ")
num1_word = (str(num1))
if bew in ["+","-","x","X",":","%","P","p"] :
num2 = float(input("\n Nummer 2: "))
num1_con = (str(num1))
num2_con = (str(num2))
if bew == "+" :
plus_out = (num1 + num2)
plus_out1 = (str(plus_out))
print ("\n" + num1_con +" + " + num2_con + " = " + plus_out1)
elif bew == "x" or "X" :
x_out = (num1 * num2)
x_out1 = (str(x_out))
print ("\n" + num1_con +" x " + num2_con + " = " + x_out1)
elif bew == "-" :
minus_out = (num1 - num2)
minus_out1 = (str(minus_out))
print ("\n" + num1_con +" - " + num2_con + " = " + minus_out1)
elif bew == ":" :
divide_out = (num1 / num2)
divide_out1 = (str(divide_out))
print ("\n" + num1_con +" : " + num2_con + " = " + divide_out1)
elif bew == "q" or "Q":
quad_out = (num1 * num1)
quad_out1 = (str(quad_out))
print ("\n " + quad_out1 )
elif bew == "w" or "W":
sqrt1 = math.sqrt (num1)
print (sqrt1)
elif bew == "%":
pro_out = (num1 / num2)
pro_out1 = (pro_out * 100)
pro_out2 = (str(pro_out1))
print (pro_out2 + "%")
elif bew == "P" or "p":
pow_out = (num1 ** num2)
pow_out1 = (str(pow_out))
print ("\n" + num1_con + " tot de kracht van " + num2_con + " is " + pow_out1)
elif q == "n" or "N":
num1 = float(input("\n Nummer 1: "))
bew = input("\n Bewerkingsteken: ")
num1_word = (str(num1))
if bew in ["+","-","x","X",":","%","P","p"] :
num2 = float(input("\n Nummer 2: "))
num1_con = (str(num1))
num2_con = (str(num2))
if bew == "+" :
plus_out = (num1 + num2)
plus_out1 = (str(plus_out))
print ("\n" + num1_con +" + " + num2_con + " = " + plus_out1 + "n")
elif bew == "x" or "X" :
x_out = (num1 * num2)
x_out1 = (str(x_out))
print ("\n" + num1_con +" x " + num2_con + " = " + x_out1 + "\n")
elif bew == "-" :
minus_out = (num1 - num2)
minus_out1 = (str(minus_out))
print ("\n" + num1_con +" - " + num2_con + " = " + minus_out1 + "\n")
elif bew == ":" :
divide_out = (num1 / num2)
divide_out1 = (str(divide_out))
print ("\n" + num1_con +" : " + num2_con + " = " + divide_out1 + "\n")
elif bew == "q" or "Q":
quad_out = (num1 * num1)
quad_out1 = (str(quad_out))
print ("\n " + quad_out1 + "\n")
elif bew == "w" or "W":
sqrt1 = math.sqrt (num1)
print (sqrt1 + "\n")
elif bew == "%":
pro_out = (num1 / num2)
pro_out1 = (pro_out * 100)
pro_out2 = (str(pro_out1))
print (pro_out2 + "% \n")
elif bew == "P" or "p":
pow_out = (num1 ** num2)
pow_out1 = (str(pow_out))
print ("\n" + num1_con + " tot de kracht van " + num2_con + " is " + pow_out1 + "\n")
else:
num1 = float(input("\n Nummer 1: "))
bew = input("\n Bewerkingsteken: ")
num1_word = (str(num1))
if bew in ["+","-","x","X",":","%","P","p"] :
num2 = float(input("\n Nummer 2: "))
num1_con = (str(num1))
num2_con = (str(num2))
if bew == "+" :
plus_out = (num1 + num2)
plus_out1 = (str(plus_out))
print ("\n" + num1_con +" + " + num2_con + " = " + plus_out1)
elif bew == "x" or "X" :
x_out = (num1 * num2)
x_out1 = (str(x_out))
print ("\n" + num1_con +" x " + num2_con + " = " + x_out1)
elif bew == "-" :
minus_out = (num1 - num2)
minus_out1 = (str(minus_out))
print ("\n" + num1_con +" - " + num2_con + " = " + minus_out1)
elif bew == ":" :
divide_out = (num1 / num2)
divide_out1 = (str(divide_out))
print ("\n" + num1_con +" : " + num2_con + " = " + divide_out1)
elif bew == "q" or "Q":
quad_out = (num1 * num1)
quad_out1 = (str(quad_out))
print ("\n " + quad_out1 )
elif bew == "w" or "W":
sqrt1 = math.sqrt (num1)
print (sqrt1)
elif bew == "%":
pro_out = (num1 / num2)
pro_out1 = (pro_out * 100)
pro_out2 = (str(pro_out1))
print (pro_out2 + "%")
elif bew == "P" or "p":
pow_out = (num1 ** num2)
pow_out1 = (str(pow_out))
print ("\n" + num1_con + " tot de kracht van " + num2_con + " is " + pow_out1)
elif q == "n" or "N":
num1 = float(input("\n Nummer 1: "))
bew = input("\n Bewerkingsteken: ")
num1_word = (str(num1))
if bew in ["+","-","x","X",":","%","P","p"] :
num2 = float(input("\n Nummer 2: "))
num1_con = (str(num1))
num2_con = (str(num2))
if bew == "+" :
plus_out = (num1 + num2)
plus_out1 = (str(plus_out))
print ("\n" + num1_con +" + " + num2_con + " = " + plus_out1 + "n")
elif bew == "x" or "X" :
x_out = (num1 * num2)
x_out1 = (str(x_out))
print ("\n" + num1_con +" x " + num2_con + " = " + x_out1 + "\n")
elif bew == "-" :
minus_out = (num1 - num2)
minus_out1 = (str(minus_out))
print ("\n" + num1_con +" - " + num2_con + " = " + minus_out1 + "\n")
elif bew == ":" :
divide_out = (num1 / num2)
divide_out1 = (str(divide_out))
print ("\n" + num1_con +" : " + num2_con + " = " + divide_out1 + "\n")
elif bew == "q" or "Q":
quad_out = (num1 * num1)
quad_out1 = (str(quad_out))
print ("\n " + quad_out1 + "\n")
elif bew == "w" or "W":
sqrt1 = math.sqrt (num1)
print (sqrt1 + "\n")
elif bew == "%":
pro_out = (num1 / num2)
pro_out1 = (pro_out * 100)
pro_out2 = (str(pro_out1))
print (pro_out2 + "% \n")
elif bew == "P" or "p":
pow_out = (num1 ** num2)
pow_out1 = (str(pow_out))
print ("\n" + num1_con + " tot de kracht van " + num2_con + " is " + pow_out1 + "\n")
Aucun commentaire:
Enregistrer un commentaire