User:Andrewc10/python

Hi I am AndrewC10 and I am somewhat good at python

programs

I use pycharm to run my programs

calculator

I like to create calculators using python.

Calculator Version 1

This program does not work, therefore it will not be posted

Calculator Version 2 Version Alpha

recordcal = input("Do You Want Me To Record The Calculations?")
calculist = []
i = 0
def Basiccal():  
    basicfunction = input("""What would you like me to do? +, -, *, /, ^, modulo or, square root, or: repeat previous calculations(type rpc).You may type quit at any time to exit the program""").strip().lower() 
    if basicfunction == "quit":
        quit()
    if basicfunction != "+" and basicfunction != "-" and basicfunction != "*" and basicfunction != "/" and basicfunction != "^" and basicfunction != "square root" and basicfunction != "modulo" and basicfunction != "quit" and basicfunction != "repeat previous calculations" and basicfunction != "rpc":
        print("Sorry, I do not recognize the command please try again.") 
        Basiccal() 
        pass
    if basicfunction == "rpc": 
        i = 0
        if not calculist:
            print("No Calculation Yet!") 
            Basiccal()
            pass
        else:
            i = 0
            while i != len(calculist):
                print(calculist[i])
                i = i+1
            Basiccal()
            pass
    else:
      pass
    basicinputone = input("please input the first number").strip().lower()
    if basicinputone == "quit": 
        quit()
    try:                        
      float(basicinputone)
    except ValueError:
      print("ERROR ERROR!", basicinputone, "IS NOT A NUMBER")
      Basiccal()
      pass
    basicinputone = float(basicinputone)
    if basicfunction == "square root":
      print("No need for second number in the Square Root function")
      basicinputtwo = 1
    else:
      basicinputtwo = input("please enter the second number").strip().lower()
      if basicinputtwo == "quit":
          quit()
    try:
      float(basicinputtwo)
    except ValueError:
      print("ERROR ERROR!", basicinputtwo, "IS NOT A NUMBER")
      Basiccal()
      pass
    basicinputtwo = float(basicinputtwo)
    if basicfunction == "+":
      print(basicinputone+basicinputtwo)
      sss = "{} + {} = {}".format(basicinputone, basicinputtwo, int(basicinputone) + int(basicinputtwo)) 
    elif basicfunction == "-":
      print(basicinputone-basicinputtwo)
      sss = "{} - {} = {}".format(basicinputone, basicinputtwo, int(basicinputone) - int(basicinputtwo))
    elif basicfunction == "*":
      print(basicinputone*basicinputtwo)
      sss = "{} * {} = {}".format(basicinputone, basicinputtwo, int(basicinputone) * int(basicinputtwo))
    elif basicfunction == "^":
      print(basicinputone**basicinputtwo)
      sss = "{} ^ {} = {}".format(basicinputone, basicinputtwo, int(basicinputone) ** int(basicinputtwo))
    elif basicfunction == "modulo":
        print(basicinputone % basicinputtwo)
        sss = "{} mod {} = {}".format(basicinputone, basicinputtwo, int(basicinputone) % int(basicinputtwo))
    elif basicfunction == "square root":
        import math
        sqrt = math.sqrt(basicinputone)
        print(math.sqrt(basicinputone))
        sss = "√{} = {}".format(basicinputone, sqrt)
    elif (basicinputtwo == 0) : 
        if (basicinputone == 0) :
            print("Undefined")
        else:
            print("Infinity")
    else:
        print(basicinputone / basicinputtwo)
        sss = "{} / {} = {}".format(basicinputone, basicinputtwo, int(basicinputone) / int(basicinputtwo))
    calculist.append(sss) 
    Basiccal()
print(Basiccal())

Calculator Version 2 Version Beta

basicfunction = ""
calculist = []
i = 0
while basicfunction != "quit":
  def Basiccal():
      basicfunction = input("""What would you like me to do? +, -, *, /, ^, modulo or, square root, or: repeat previous calculations(type rpc).
  You may type quit at any time to exit the program""").strip().lower()
      if basicfunction == "quit":
          quit()
          return
      if basicfunction not in ["+", "-", "*", "/", "^", "square root", "modulo", "quit", "rpc"]:
          print("Sorry, I do not recognize the command please try again.")
          return
      elif basicfunction == "rpc":
          if not calculist:
              print("No Calculation Yet!")
              return
          else:
            i = 0
            while i != len(calculist):
              print(calculist[i])
              i = i+1
              Basiccal()
              pass
      else:
        print("okay")  
      basicinputone = input("please input the first number").strip().lower()
      if basicinputone == "quit":
          quit()
      try:
          float(basicinputone)
      except ValueError:
          print("ERROR ERROR!", basicinputone, "IS NOT A NUMBER")
          Basiccal()
          pass
      basicinputone = float(basicinputone)
      if basicfunction == "square root":
          print("No need for second number in the Square Root function")
          basicinputtwo = 1
      else:
          basicinputtwo = input("please enter the second number").strip().lower()
          if basicinputtwo == "quit":
              quit()
      try:
          float(basicinputtwo)
      except ValueError:
          print("ERROR ERROR!", basicinputtwo, "IS NOT A NUMBER")
          Basiccal()
          pass
      basicinputtwo = float(basicinputtwo)
      result = -1
      if basicfunction == "+":
        result = basicinputone + basicinputtwo
      elif basicfunction == "-":
        result = basicinputone - basicinputtwo
      elif basicfunction == "*":
        result = basicinputone * basicinputtwo
      elif basicfunction == "^":
        result = basicinputone ** basicinputtwo
      elif basicfunction == "modulo":
        result = int(basicinputone) % int(basicinputtwo)
      elif basicfunction == "square root":
          import math
          result = math.sqrt(basicinputone)
      elif basicfunction == "/":
        if basicinputtwo == 0:
          result = "Infinity"
        else:
          result = int(basicinputone) / int(basicinputtwo)
      sss = "{} {} {} = {}".format(basicinputone, basicfunction, basicinputtwo, result)
      print(result)
      calculist.append(sss)
      Basiccal()
Basiccal()

Calculator Version 2 Version Gamma

import math
mylist = []
i=0

def notanumber(a):
    try:
        float(a)
    except ValueError:
        return "ERROR ERROR! NOT A NUMBER"


while True:
    op = input("""What would you like me to do? +, -, *, /, ^, modulo or, square root, or: repeat previous calculations(type rpc).
  You may type quit at any time to exit the program""").strip().lower()
    if op not in ["+", "-", "*", "/", "^", "square root", "modulo", "rpc"]:
        print("not a valid function")
        break
    if op == "rpc":
        if mylist == []:
            print("no calculations yet")
        else:
            while i != len(mylist):
                print(mylist[i])
                i = i + 1
    else:
        num1 = input("enter first number").lower().strip()
        if notanumber(num1) == "ERROR ERROR! NOT A NUMBER":
          break
        num1 = float(num1)
        num2 = input("enter second number").lower().strip()
        if notanumber(num2) == "ERROR ERROR! NOT A NUMBER":
          break
        num2 = float(num2)
        if op == "+":
            result = num1 + num2
        elif op == "-":
            result = num1 - num2
        elif op == "*":
            result = num1 * num2
        elif op == "^":
            result = num1 ** num2
        elif op == "modulo":
            result = float(num1) % float(num2)
        elif op == "square root":
            result = math.sqrt(num1)
        elif op == "/":
            if num2 == 0:
                result = "Infinity"
            else:
                result = float(num1) / float(num2)
        else:
            result = "problem"
        print(result)
        sss = "{} {} {} = {}".format(num1, op, num2, result)
        mylist.append(sss)

Calculator Version 2 Version Delta

import math
mylist = []
i=0
def diviser(diva):
    divlist = []
    diva = int(diva)
    for divx in range(1, (diva+1)):
        if diva % divx == 0:
            divlist.append(divx)
    return divlist


def gcf(gcfnum1, gcfnum2):
    GCFlist = []
    gcfnum1 = diviser(gcfnum1)
    gcfnum2 = diviser(gcfnum2)
    for gcfnumber in gcfnum1:
        if gcfnumber in gcfnum2:
            GCFlist.append(gcfnumber)
    return max(GCFlist)


def lcm(lcmnum3, lcmnum4):
    lcmv = lcmnum3*lcmnum4
    float(lcmv)
    lcmz = gcf(lcmnum3, lcmnum4)
    float(lcmz)
    return lcmv/lcmz


def notanumber(a):
    try:
        float(a)
    except ValueError:
        return "ERROR ERROR! NOT A NUMBER"


def is_prime(pria):
    for piab in range(2, int(pria//2)):
        if pria % piab == 0:
            return "not prime"
    return "prime"


while True:
    op = input("""What would you like me to do? +, -, *, /, ^, modulo or, square root, or: repeat previous calculations(type rpc), please type advanced to view advanced options.
  You may type quit at any time to exit the program""").strip().lower()
    if op not in ["+", "-", "*", "/", "^", "square root", "modulo", "rpc", "advanced", "!", "||", "gcf", "lcm", "prime?", "btb"]:
        print("not a valid function")
        break

    if op == "advanced":
        print("""advanced functions: !, base to base conversion (type btb), ||, GCF, LCM, prime factorization (type pf)
or test is a number is prime (type prime?)""")
        result = ""

    elif op == "rpc":
        if mylist == []:
            print("no calculations yet")
        else:
            while i != len(mylist):
                print(mylist[i])
                i = i + 1
    elif op in ["!", "btb", "||", "gcf", "lcm", "pf", "prime?"]:
        if op == "!":
            fac = input("what number would you like to factorial")
            if notanumber(fac) == "ERROR ERROR! NOT A NUMBER":
                break
            fac = int(fac)
            for adfact in range(1, fac):
                fac = adfact * fac
                result = fac
        if op == "||":
            absin = input("absolute value what")
            if notanumber(absin) == "ERROR ERROR! NOT A NUMBER":
                break
            result = 0-float(absin)
        if op == "gcf":
            result = gcf(input("GCF num1"), input("gcf num2"))
        if op == "lcm":
            result = lcm(int(input("lcm num 1")), int(input("lcm num 2")))
        if op == "prime?":
            isprvar = int(input("your number...?"))
            result = "The number: {} is {}".format(isprvar, is_prime(isprvar))
        if op == "btb":
            an = int(input("What number do you want to convert into a different base?"))
            ab = int(input("What base are you converting " + str(an) + " into?"))
            ax = ''
            ad = an
            while ad != 0:
                ar = ad % ab
                ax = str(ar) + ax
                ad = int((ad - ar) / ab)
            print("Base ", str(ab), ": ", ax)
            result = ""
    else:
        num1 = input("enter first number").lower().strip()
        if notanumber(num1) == "ERROR ERROR! NOT A NUMBER":
          break
        num1 = float(num1)
        num2 = input("enter second number").lower().strip()
        if notanumber(num2) == "ERROR ERROR! NOT A NUMBER":
          break
        num2 = float(num2)
        if op == "+":
            result = num1 + num2
        if op == "-":
            result = num1 - num2
        if op == "*":
            result = num1 * num2
        elif op == "^":
            result = num1 ** num2
        elif op == "modulo":
            result = float(num1) % float(num2)
        elif op == "square root":
            result = math.sqrt(num1)
        elif op == "/":
            if num2 == 0:
                result = "Infinity"
            else:
                result = float(num1) / float(num2)
        sss = "{} {} {} = {}".format(num1, op, num2, result)
        mylist.append(sss)
    print(result)

Calculator Version 2 Version Epsilon

mylist = []
import math
sss = ""
def diviser(diva):
    divlist = []
    for divx in range(1, (diva+1)):
        if diva % divx == 0:
            divlist.append(divx)
    return divlist


while True:
    op = input("what do you want to do?\ntype listop for list of operations").lower().strip()
    if op not in ["+", "-", "*", "/", "^", "sqrt", "modulo", "rpc", "advanced", "!", "||", "gcf", "lcm", "prime?", "btb", "listop", "temp", "sin", "tan", "cos"]:
        print("invalid operation")
        break
    if op == "listop":
        print("+ : addition\n- : subtraction\n* : multiplication\n/ : division\n^ : exponents\nsqrt : radicals fist number is the radicand, second number is the index\nmod : modulo\n"
              "rpc : repeat preveious Calculations\n! : factorial\n|| : absoulute value\ngcf\nlcm\nbtb : base to base\ntemp : FtoC or CtoF conversion\nsin : sine\ncos : cosine\ntan : tangent")
    if op in ["+", "-", "*", "/", "^", "sqrt"]:
        basicnum1 = float(input("first number"))
        basicnum2 = float(input("second number"))
        if op == "+":
            result = basicnum1 + basicnum2
        if op == "-":
            result = basicnum1 - basicnum2
        if op == "*":
            result = basicnum1 * basicnum2
        if op == "/":
            if basicnum1 == 0:
                result = "0, though technically Undefined"
            if basicnum2 == 0:
                result = "Undefined"
            else:
                result = basicnum1/basicnum2
        if op == "^":
            if basicnum1 == "0" and basicnum2 == "0":
                result = "Undifined"
            else:
                result = basicnum1**basicnum2
        if op == "sqrt":
            result = math.sqrt(basicnum1)
        if op == "mod":
            result = basicnum1%basicnum2
        sss = "{} {} {} = {}".format(basicnum1, op, basicnum2, result)
    elif op == "!":
        facd = int(input("what number would you like to factorial"))
        fac = facd
        for adfact in range(1, fac):
            fac = adfact * fac
            sss = "{}! = {}".format(facd, fac)
    elif op == "||":
        absin = float(input("absolute value what"))
        sss = "|{}| = {}".format(absin, 0-absin)
    elif op == "temp":
        tempa = input("f to c (type ftc) or c to f (type ctf)").lower().strip()
        if tempa == "ftc":
            tempb = float(input("Fahrenheit value?"))
            tempc = (tempb - 32) * 5 / 9
            sss = "{} Fahrenheit =\n{} Celsius".format(tempb, tempc)
        if tempa == "ctf":
            tempd = float(input("Celsius value?"))
            tempe = tempd *  9 / 5 +32
            sss = "{} Celsius =\n{} Fahrenheit".format(tempd, tempe)
    elif op == "gcf":
        gcfa = int(input("gcf num 1"))
        gcfb = int(input("gcf num 2"))
        sss = "gcf({}, {}) = {}".format(gcfa, gcfb, math.gcd(gcfa, gcfb))
    elif op == "lcm":
        lcma = int(input("lcm num 1"))
        lcmb = int(input("lcm num 2"))
        sss = "lcm({}, {}) = {}".format(lcma, lcmb, (lcma*lcmb/math.gcd(lcma, lcmb)))
    elif op == "rpc":
        i = 0
        if mylist == []:
            print("no calculations yet")
        else:
            sss = "\n".join(mylist)
    elif op == "prime?":
        pria = int(input("what number would you like to check"))
        for piab in range(2, int(pria // 2)):
            if pria % piab == 1:
                sss = "{} is not prime".format(pria)
                break
        sss = "{} is prime".format(pria)
    elif op == "sin":
        sinin = float(input("sine what"))
        sss = "sin({}°) = {}".format(sinin, math.sin(sinin))
    elif op == "tan":
        tanin = float(input("tangent what"))
        sss = "tan({}°) = {}".format(tanin, math.tan(tanin))
    elif op == "cos":
        cosin = float(input("cosine what"))
        sss = "cos({}°) = {}".format(cosin, math.cos(cosin))
    elif op == "btb":
        btb = input("[to] base 10 or [from] base 10").strip().lower()
        if btb == "to":
            from_num = int(input("number?"))
            base = int(input("what base is it in"))
            num_base_10 = 0
            exp = 0
            while from_num > 0:
                num_base_10 += (from_num % 10) * (base ** exp)
                from_num = from_num // 10
                exp += 1
            print(num_base_10)
        if btb == "from":
            basex2 = int(input("number..."))
            basey = int(input("to what base"))
            basex = basex2
            baselist = []
            while basex%basey != basex:
                baselist.insert(0, str(basex % basey))
                basex = basex // basey
            baselist.insert(0, str(basex % basey))
            base1x = "".join(baselist)
            sss = "base 10: {} = base {}: {}".format(basex2, basey, base1x)
    print(sss)
    mylist.append(sss)

Calculator Version 2 Version Zeta

mylist = []
import math
sss = ""
def nan(nana):
    try:
        float(nana)
    except ValueError:
        print("Number Error")
        quit()
    return float(nana)

while True:
    op = input("what do you want to do?\ntype listop for list of operations").lower().strip()
    if op not in ["+", "-", "*", "/", "^", "sqrt", "modulo", "rpc", "advanced", "!", "||", "gcf", "lcm", "prime?", "btb", "listop", "temp", "sin", "tan", "cos"]:
        print("invalid operation")
        break
    if op == "listop":
        print("+ : addition\n- : subtraction\n* : multiplication\n/ : division\n^ : exponents\nsqrt : radicals fist number is the radicand, second number is the index\nmod : modulo\n"
              "rpc : repeat preveious Calculations\n! : factorial\n|| : absoulute value\ngcf\nlcm\nbtb : base to base\ntemp : FtoC or CtoF conversion\nsin : sine\ncos : cosine\ntan : tangent")
    if op in ["+", "-", "*", "/", "^", "sqrt", "mod"]:
        basicnum1 = nan(input("first number"))
        basicnum2 = nan(input("second number"))
        if op == "+":
            result = basicnum1 + basicnum2
        if op == "-":
            result = basicnum1 - basicnum2
        if op == "*":
            result = basicnum1 * basicnum2
        if op == "/":
            if basicnum1 == 0:
                result = "0, though technically Undefined"
            elif basicnum2 == 0:
                result = "Undefined"
            else:
                result = basicnum1/basicnum2
        if op == "^":
            if basicnum1 == "0" and basicnum2 == "0":
                result = "Undifined"
            else:
                result = basicnum1**basicnum2
        if op == "sqrt":
            result = math.sqrt(basicnum1)
        if op == "mod":
            result = basicnum1%basicnum2
        sss = "{} {} {} = {}".format(basicnum1, op, basicnum2, result)
    elif op == "!":
        facd = int(nan(input("what number would you like to factorial")))
        fac = facd
        for adfact in range(1, fac):
            fac = adfact * fac
            sss = "{}! = {}".format(facd, fac)
    elif op == "||":
        absin = nan(input("absolute value what"))
        sss = "|{}| = {}".format(absin, abs(absin))
    elif op == "temp":
        tempa = input("f to c (type ftc) or c to f (type ctf)").lower().strip()
        if tempa == "ftc":
            tempb = nan(input("Fahrenheit value?"))
            tempc = (tempb - 32) * 5 / 9
            sss = "{} Fahrenheit =\n{} Celsius".format(tempb, tempc)
        if tempa == "ctf":
            tempd = nan(input("Celsius value?"))
            tempe = tempd *  9 / 5 +32
            sss = "{} Celsius =\n{} Fahrenheit".format(tempd, tempe)
    elif op == "gcf":
        gcfa = int(nan(input("gcf num 1")))
        gcfb = int(nan(input("gcf num 2")))
        sss = "gcf({}, {}) = {}".format(gcfa, gcfb, math.gcd(gcfa, gcfb))
    elif op == "lcm":
        lcma = int(nan(input("lcm num 1")))
        lcmb = int(nan(input("lcm num 2")))
        sss = "lcm({}, {}) = {}".format(lcma, lcmb, (lcma*lcmb/math.gcd(lcma, lcmb)))
    elif op == "rpc":
        i = 0
        if mylist == []:
            print("no calculations yet")
        else:
            sss = "\n".join(mylist)
    elif op == "prime?":
        pria = int(input("what number would you like to check"))
        for piab in range(2, int(pria // 2)):
            if pria % piab == 1:
                sss = "{} is not prime".format(pria)
                break
        sss = "{} is prime".format(pria)
    elif op == "sin":
        sinin = nan(input("sine what"))
        sss = "sin({}°) = {}".format(sinin, math.sin(sinin))
    elif op == "tan":
        tanin = nan(input("tangent what"))
        sss = "tan({}°) = {}".format(tanin, math.tan(tanin))
    elif op == "cos":
        cosin = nan(input("cosine what"))
        sss = "cos({}°) = {}".format(cosin, math.cos(cosin))
    elif op == "btb":
        btb = input("[to] base 10 or [from] base 10").strip().lower()
        if btb == "to":
            from_num = int(nan(input("number?")))
            base = int(nan(input("what base is it in")))
            num_base_10 = 0
            exp = 0
            while from_num > 0:
                num_base_10 += (from_num % 10) * (base ** exp)
                from_num = from_num // 10
                exp += 1
            print(num_base_10)
        if btb == "from":
            basex2 = int(nan(input("number...")))
            basey = int(nan(input("to what base")))
            basex = basex2
            baselist = []
            while basex%basey != basex:
                baselist.insert(0, str(basex % basey))
                basex = basex // basey
            baselist.insert(0, str(basex % basey))
            base1x = "".join(baselist)
            sss = "base 10: {} = base {}: {}".format(basex2, basey, base1x)
    print(sss)
    mylist.append(sss)
    if op in ["listop", "rpc"]:
        mylist.pop()

Calculator Version 2 Version Eta--The Super Calculator

This is still in development please wait patiently

Invalid username
Login to AoPS