How do I get an answer variable to match up with what the user adds in a calculator? [closed]

I’m making a calculator in python and I added a number_choice variable to make it more like the real thing, the problem is one variable for the answer but the number_choice wont match up, for instance, say you boot up your calculator and it ask you how many sequence of numbers you want to put in and the only choices you have are 2 but you want more and it wont let you, here is the code.

import time

def main():
    calculator()

def calculator():
    while True:
        operation = str(input("Addition or subtraction? - "))
        number_choice = int(input("How many numbers? - ")) #! Fix number solution!
        
        if number_choice < 2:
            print("\nYou have to choose more than 1\n") #? How do I get answer variable to match up with what the user adds?
            continue
        
        first_number = str(input("\nInput first number - "))
        second_number = str(input("Input second number - "))
        
        if operation == "a":
            answer = int(first_number) + int(second_number) #* This variable doesnt sync well with line 9 and line 12.
        elif operation == "s":
            answer = int(first_number) - int(second_number)
                
        #All good here (I think).
        print("Your answer is " + str(answer) + "\n")
        play_again = str(input("Do you want to play again? - "))
        
        if play_again == "y":
            print("Restarting...\n")
            continue
        else:
            print("Have a good day!")
            time.sleep(3)
            break

main()

I’ve tried moving the some variables around and thinking of solutions but I’ve got nothing.

  • Please include the sample input, actual output and the expected output.

    – 

  • Store the numbers in a list. That way you can accept any number of inputs. Use number_choice in a loop to get those numbers.

    – 

  • Welcome to Stack Overflow. Please read How to Ask and How do I ask and answer homework questions?. We will not write code to specification for you here. Plagiarism is a serious academic offense; aside from that, we require a specific question – which will come out of your best attempt to understand and analyze the task, identify the logical steps to solve the problem, and figure out where you are actually stuck. Make sure to check if the issue is already addressed in another question.

    – 

Leave a Comment