carmenie
carmenie

Reputation: 1

TypeError: input expected 1 argument at most got 4

making a random one digit number addition problem generator and i ended up with this error

import random 

num = random.randint(0,9)
bothnumbers = []
score = 0

for i in range (10):
  q = bothnumbers.append(int(input("What is the answer to: " ,num,"+",num )))
  answer = sum(bothnumbers)
  if q == answer:
      score=+1

print("Your score is: ",score)

Upvotes: -1

Views: 1414

Answers (2)

Tim Roberts
Tim Roberts

Reputation: 54767

bothnumbers.append returns nothing, so q is going to be None. I don't know what you're trying to do with bothnumbers. You never compute num+num, so you have no way of checking the answer. And your test is always going to ask the same question every time. And you never initialized score.

I think you want this:

import random
score = 0
for _ in range(10):
    num1 = random.randint(0,9)
    num2 = random.randint(0,9)
    q = int(input(f"What is the answer to {num1}+{num2}? " ))
    if q == num1+num2:
        score += 1

print( f"Your score was {score}")

Upvotes: 0

Cory Kramer
Cory Kramer

Reputation: 118001

input accepts a single string so instead of

input("What is the answer to: " ,num,"+",num )

You could do

input(f"What is the answer to: {num} + {num}")

Upvotes: 3

Related Questions