0

why won't it work? :( why won't the if and while function accept my in statement

"""try to make it repeat!""" repeat = ['y','yes'] """Imports here""" from math import pi """Calculator""" #Definitions def add(x,y): return x+y def sub(x,y): return x-y def div(x,y): return x/y def mul(x,y): return x*y def square(x): return x**2 def SquareRoot(x): return x**(1/2) """Dictionaries""" #Warning:Extremely messy! division = ["Division","Divide","/","div"] multiplication = ["*","x","times","multiply","multiplication","multiple"] subtraction = ["-",'minus','subtract','subtraction'] addition = ['+','plus','addition','add'] root = ['root','squareroot','square root'] square = ['square','squared','power 2'] #Code while repeat in repeat: choice = input("Input type of operation!(+,-,*,/,^2,^1/2)") if choice in division or multiplication or subtraction or addition: num1 = int(input("ENTER FIRST NUMBER")) num2 = int(input("ENTER SECOND NUMBER")) if choice in addition: print(num1,"+",num2,"=",(num1+num2)) elif choice in subtraction: print(num1,"-",num2,"=",(num1-num2)) elif choice in division: print(num1,"/",num2,"=",(num1/num2)) elif choice in multiplication: print(num1,"*",num2,"=",(num1*num2)) elif choice in root: num3 = int(input("ENTER A NUMBER")) if choice in square: print(num3,"^2","=",(num3**2)) elif choice in root: print(num3,"^(1/2)","=",(num3**(1/2))) else: print("continue") else: print("something went wrong!", print(pi)) repeat = input("Do you want to perform another calcualtion?(Y/N)")

15th Nov 2016, 1:39 PM
Dave Matthew
Dave Matthew - avatar
1 Réponse
+ 4
Your 'repeat' var is not assigned a value when the while loop runs. Have you tried 'while True', then if user enters repeat = 'N' , you can simply 'break' out of the loop.
23rd Nov 2016, 2:11 PM
Jay Azurin
Jay Azurin - avatar