Пример #1
0
def get_answer(MathParts):
    Arguments = list()
    TempArgument = list()
    for Unit in MathParts:
        if Unit != " ":
            if Unit in IsNum:
                TempArgument.append(Unit)
            else:
                TempArgument = "".join(TempArgument)
                TempArgument = float(TempArgument)
                Arguments.append(TempArgument)
                TempArgument = []
        if Unit in IsOp:
            Arguments.append(Unit)
    TempArgument = "".join(TempArgument)
    TempArgument = float(TempArgument)
    Arguments.append(TempArgument)
    TempArgument = []
    Arguments.append(Unit)
    answer = operation(Arguments[1], Arguments[0], Arguments[2])  #get answer
    answer = str(answer)  #change to string
    answer = list(answer)  #split into list
    return answer
Пример #2
0
def get_answer(MathParts):
    Arguments = list() 
    TempArgument = list()
    for Unit in MathParts:
        if Unit != " ":
            if Unit in IsNum:
                TempArgument.append(Unit)
            else:
                TempArgument = "".join(TempArgument)
                TempArgument = float(TempArgument)
                Arguments.append(TempArgument)
                TempArgument = []
        if Unit in IsOp:
             Arguments.append(Unit)
    TempArgument = "".join(TempArgument)
    TempArgument = float(TempArgument)
    Arguments.append(TempArgument)
    TempArgument = []
    Arguments.append(Unit) 
    answer = operation(Arguments[1],Arguments[0],Arguments[2])  #get answer
    answer = str(answer)                                        #change to string
    answer = list(answer)                                       #split into list
    return answer
Пример #3
0
 def output(self):
     self.text = str_proc(self.text)
     self.screen.setText(str(operation(self.text)))
     self.text = ''
Пример #4
0
def do_Ops(MathParts, Ops):

    Looper = 0
    Arguments = []
    First_arg = []
    Secnd_arg = []
    while (Looper < len(MathParts)):
        if (MathParts[Looper] in Ops and Looper != 0):
            First_arg = []
            Secnd_arg = []
            List_len = len(MathParts)
            Op = MathParts[Looper]  #gets op
            First_num = Looper - 1  #starts pull for first number
            Secnd_num = Looper + 1  #starts pull for second number
            First_bool = True
            Secnd_bool = True
            while First_bool == True:  #while the value is a num
                if First_num != -1:
                    if MathParts[First_num] in IsNum and not ("-"
                                                              in First_arg):
                        First_arg.append(
                            MathParts[First_num])  #add to first num list
                        First_num = First_num - 1  #decrement loop
                    else:
                        First_bool = False
                else:
                    First_bool = False
            while Secnd_bool == True:  #while the value is a num
                if Secnd_num != List_len:
                    if MathParts[Secnd_num] == "-":
                        Secnd_arg.append("-")
                        Secnd_num = Secnd_num + 1
                    if MathParts[Secnd_num] in IsNum and MathParts[
                            Secnd_num] != "-":
                        Secnd_arg.append(
                            MathParts[Secnd_num])  #add to second num list
                        Secnd_num = Secnd_num + 1  #increment loop
                    else:
                        Secnd_bool = False
                else:
                    Secnd_bool = False
            Insert_point = First_num + 1  #save point to save answer back into array
            First_arg = list(reversed(First_arg))  #get the correct first value
            if "-" in First_arg:
                First_arg.remove("-")
                First_arg = "".join(First_arg)
                First_arg = float(First_arg)
                First_arg = -1 * First_arg
            else:
                First_arg = "".join(First_arg)
                First_arg = float(First_arg)

            if "-" in Secnd_arg:
                Secnd_arg.remove("-")
                Secnd_arg = "".join(Secnd_arg)
                Secnd_arg = float(Secnd_arg)
                Secnd_arg = -1 * Secnd_arg
            else:
                Secnd_arg = "".join(Secnd_arg)
                Secnd_arg = float(Secnd_arg)

            Insert = operation(Op, First_arg,
                               Secnd_arg)  #get answer of equations
            Insert = str(Insert)
            Insert = list(Insert)

            Del_len = (Secnd_num - 1) - (First_num + 1
                                         )  #start point to remove from string
            Del = First_num + 1
            Del_loop = 0  #stop point to remove from string
            while (Del_loop <= Del_len):
                del MathParts[Del]  #remove value
                Del_loop = Del_loop + 1
            for num in Insert:
                MathParts.insert(Insert_point, num)
                Insert_point = Insert_point + 1
            Answer = "".join(MathParts)
            Looper = 0
        else:
            Looper = Looper + 1
    return MathParts
Пример #5
0
# will try to add more features down the line #
###############################################

###################
#Class importation#
###################
import sys
from operation import *
##################################################
#Query user for input, exit will be string "exit"#
##################################################
op = ""
last_op =""
answer = 0
print "Welcome! Use the calculator to do what you need, type \"help\" to get a list of commands. Type \"exit\" to exit the program.\n"
while (op != "exit" and op != "exit "):
	last_op=op
	a = get_First_Num(answer)
	if(a=="d" or a=="d " or a=="D" or a=="D  "):
            answer = operation(last_op,answer,answer)
            print"{}".format(answer)
            print "_____________\n"
        else:
	    op = raw_input("op: ")
	    answer=operation(op,a,answer)
            print "{}".format(answer)
            print "_____________\n"
if(op=="exit" or op=="exit "):
	print "Thank you, see you soon!"
	sys.exit(0)
Пример #6
0
def do_Ops(MathParts, Ops):
    
    Looper = 0
    Arguments = []
    First_arg = []
    Secnd_arg = []
    while (Looper < len(MathParts)):
        if (MathParts[Looper] in Ops and Looper != 0):
            First_arg = []
            Secnd_arg= []
            List_len = len(MathParts)
            Op = MathParts[Looper]                                                    #gets op
            First_num = Looper-1                                                    #starts pull for first number 
            Secnd_num = Looper+1                                                      #starts pull for second number
            First_bool = True
            Secnd_bool = True
            while First_bool == True:                                      #while the value is a num 
                if First_num != -1:
                    if MathParts[First_num] in IsNum and not("-" in First_arg):
                        First_arg.append(MathParts[First_num])                                #add to first num list
                        First_num = First_num-1                                               #decrement loop
                    else:
                            First_bool = False
                else:
                    First_bool = False
            while Secnd_bool == True:                                                 #while the value is a num
                if Secnd_num != List_len:
                    if MathParts[Secnd_num] == "-":
                        Secnd_arg.append("-")
                        Secnd_num = Secnd_num+1
                    if MathParts[Secnd_num] in IsNum and MathParts[Secnd_num] != "-":
                        Secnd_arg.append(MathParts[Secnd_num])                                #add to second num list
                        Secnd_num = Secnd_num+1                                               #increment loop
                    else:
                        Secnd_bool = False
                else:
                    Secnd_bool = False
            Insert_point = First_num+1                                                #save point to save answer back into array
            First_arg = list(reversed(First_arg))                                           #get the correct first value
            if "-" in First_arg:
               First_arg.remove("-") 
               First_arg = "".join(First_arg)
               First_arg = float(First_arg)
               First_arg = -1 * First_arg
            else:
               First_arg = "".join(First_arg)
               First_arg = float(First_arg)

            if "-" in Secnd_arg:
               Secnd_arg.remove("-") 
               Secnd_arg = "".join(Secnd_arg)
               Secnd_arg = float(Secnd_arg)
               Secnd_arg = -1 * Secnd_arg               
            else:
                Secnd_arg = "".join(Secnd_arg)
                Secnd_arg = float(Secnd_arg)

            Insert = operation(Op, First_arg, Secnd_arg)                                           #get answer of equations
            Insert = str(Insert)
            Insert = list(Insert)

            Del_len = (Secnd_num-1)-(First_num+1)                                                #start point to remove from string
            Del = First_num+1
            Del_loop = 0                                                   #stop point to remove from string
            while (Del_loop <= Del_len):
              del MathParts[Del]                                                 #remove value
              Del_loop = Del_loop+1
            for num in Insert:
                MathParts.insert(Insert_point, num)
                Insert_point = Insert_point+1
            Answer = "".join(MathParts)
            Looper = 0
        else:
            Looper = Looper+1
    return MathParts