Basic Maths Game, Python: 'input expected at most 1 arguements, got 4'
Question: I've been working with Python for a little while now, and I decided recently I
wanted to make a basic maths game that would choose a random number from a
list between 0-9, and make you add them together. If your answer was right, it
would say well done, if it was wrong, it would say try again next time.

I'm having a problem with a line of code though, because it comes up with an
error message saying:

    
    
    input expected at most 1 arguments, got 4
    

for this line of code:

    
    
    ans=int(input(num1,'+',num2,'= '))
    

I've looked it up several times, and have found answers to the problem, but
not in the way I need them. Here is the whole line of code.

    
    
    nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    import random
    num1 = random.choice(nums)
    num2 = random.choice(nums)
    sum = num1+num2
    correct_ans = sum
    ans=int(input(num1,'+',num2,'= '))
    if ans==correct_ans:
        print('Correct, Well Done!')
    else:
        print('Wrong, Try Again Next Time!')
    


Answer: ## Input takes 1 arg

You are passing 4 args to `input` which accepts only 1 argument

    
    
    input(num1,'+',num2,'= ')   # 4 args!
    

try

    
    
    question = '{} + {} ='.format(num1, num2)
    input(question)
    

## Putting it all together and discussing about types

    
    
    import random
    
    nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    
    num_1 = random.choice(nums)
    num_2 = random.choice(nums)
    
    # This sum is numeric sum not a string concat
    correct_ans = num_1 + num_2
    
    # Let's make a question string by concat of our numbers in string format
    question = '{} + {} = '.format(num_1, num_2)
    ans = input(question)
    
    # At this point ans is still a string so convert
    ans = int(ans)
    
    # Now you are comparing two ints
    if  ans == correct_ans:
        print('Correct!')
    else:
        print('Wrong!')
    

## Test run

    
    
    python math_game.py
    3 + 3 = 6
    Correct!
    
    python math_game.py
    7 + 2 = 1
    Wrong!
    

