-3

You get a Task to solve (math). - No taks with solutions below zero - No tasks with solutions that have decimal places

When the loop runs the first time everything works just fine. But after the first task it sends this error:

File ".\Task Generator.py", line 43, in input = input() TypeError: 'str' object is not callable

What is the problem with the User Input?

I tried to restructure the whole input part. But then the whole code doesn´t work.

import random
score = 0

#Loop
loop = True
while loop == True:

    tasksolution = None

    #Task generation
    badtask = True
    while badtask == True:
        nums = list(range(1, 101))
        ops = ["+", "-", "/", "x"]
        num1 = str(random.choice(nums))
        num2 = str(random.choice(nums))
        operator = random.choice(ops)
        task = str(num1 + operator + num2)

        #Tasksolution
        def add(x, y):
           return x + y
        def subtract(x, y):
           return x - y
        def multiply(x, y):
           return x * y
        def divide(x, y):
           return x / y
        if operator == "+":
            tasksolution = round(add(int(num1), int(num2)), 1)
        elif operator == "-":
            tasksolution = round(subtract(int(num1), int(num2)), 1)
        elif operator == "x":
            tasksolution = round(multiply(int(num1), int(num2)), 1)
        elif operator == "/":
            tasksolution = round(divide(int(num1), int(num2)), 1)
        if tasksolution >= 0 and (tasksolution % 2 == 0 or tasksolution % 3 == 0):
            badtask = False

    #User input
    print("Task: " + task)
    input = input()


    #Input check
    if str.isdigit(input):
        if int(input) ==  tasksolution:
            print("Correct!")
            score + 1
        elif not int(input) == tasksolution:
            print("Wrong!")
            print("The correct solution: " + str(tasksolution))
            print("You´ve solved " + str(score) + " tasks!")
            break
        else:
            print("Something went wrong :(")
    else:
        print("Please enter a number!")
        break

The loop should run without breaking except you enter a wrong solution.

Tom E.
  • 25
  • 3
  • 5
    you accidentally shadowed teh built in command `input` with a variable name. be very careful how you name your variables as its very easy to do that exact thing. rename your string to something other than input, like my_input – Nullman Mar 24 '19 at 12:04
  • You’ve overwritten the built in function `input()`. – SuperShoot Mar 24 '19 at 12:04
  • Use a different name for your variable, like `my_input` or something. Otherwise you are redefining the builtin `input` function. – Tom Karzes Mar 24 '19 at 12:08

1 Answers1

0

You've unknowingly overrided the builtin function input. Change that line to something like:

user_input = input()

... and all future references to that variable.

miike3459
  • 1,431
  • 2
  • 16
  • 32