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.