Im new to coding and am trying to make myself a calculator in pyton idle 3.10 64 bit and it isnt working

Question:

I’ve written this code so far:

OPR = input('''
which functions do you wish to use?
a for arithmetic
g for graphic
    ''')

CON = "yes"
while CON == "yes" and OPR == "a":

    OPR = input('''
    Please type in the math operation you would like to complete:
    + for addition
    - for subtraction
    * for multiplication
    / for division
    ^ for exponent
    r for radical
    a for average
    ''')

    NU1 = int(input("First number?"))
    NU2 = int(input("Second number?"))

    ADD = NU1+NU2
    SUB = NU1-NU2
    MUL = NU1*NU2
    DIV = NU1/NU2
    EXP = NU1**NU2
    RAD = NU1**(1/NU2)
    AVG = 0.5*(NU1+NU2)
    
    if OPR == "+":
        print(str(NU1) + "+" + str(NU2) + "=" + str(ADD))
        ITR = ITR + 1
    elif OPR == "+":
        print(str(NU1) + "-" + str(NU2) + "=" + str(SUB))
        ITR = ITR + 1
    elif OPR == "+":
        print(str(NU1) + "*" + str(NU2) + "=" + str(MUL))
        ITR = ITR + 1
    elif OPR == "+":
        print(str(NU1) + "/" + str(NU2) + "=" + str(DIV))
        ITR = ITR + 1
    elif OPR == "+":
        print(str(NU1) + "^" + str(NU2) + "=" + str(EXP))
        ITR = ITR + 1
    elif OPR == "+":
        print(str(NU1) + "^(1/" + str(NU2) + ")=" + str(RAD))
        ITR = ITR + 1
    elif OPR == "+":
        print(str(NU1) + " and " + str(NU2) + " average to " + str(AVG))
        ITR = ITR + 1 

I’m yet to add the graphic function or make use of the ITR variable but I think what I have so far should work. So many things go wrong depending on what I do, are there any massive errors I’m making?

Asked By: Lolosity

||

Answers:

I’ve reorganized your code so that it works the way I think you are expecting. I don’t do anything with the first question’s answer; that’s an exercise left for the reader.

opr = input('''
which functions do you wish to use?
a for arithmetic
g for graphic
    ''')

iteration = 0
while True:

    opr = input('''
    Please type in the math operation you would like to complete:
    + for addition
    - for subtraction
    * for multiplication
    / for division
    ^ for exponent
    r for radical
    a for average
    q to quit
    ''')

    if opr == 'q':
        break

    num1 = int(input("First number? "))
    num2 = int(input("Second number? "))

    if opr == "+":
        answer = num1+num2
        print(num1,  "+" , num2, "=", answer)
    elif opr == "-":
        answer = num1-num2
        print(num1,  "-" , num2, "=", answer)
    elif opr == "*":
        answer = num1*num2
        print(num1,  "*" , num2, "=", answer)
    elif opr == "/":
        answer = num1/num2
        print(num1,  "/" , num2, "=", answer)
    elif opr == "^":
        answer = num1**num2
        print(num1,  "^" , num2, "=", answer)
    elif opr == "r":
        answer = num1**(1/num2)
        print(num1,  "^(1/" , num2, ")=", answer)
    elif opr == "a":
        answer = 0.5*(num1+num2)
        print(num1,  " and " , num2, " average to ", answer)

    iteration += 1
Answered By: Tim Roberts
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.