[Solved] Where’s the mistake in my Python program? [closed]


Slightly corrected your code :

  1. Indent your code ; it is really important
  2. You can’t use the statement “return” outside a function
  3. Cast “answer” to int if you want to compare it to “a * b” OR cast a * b to string

Here is the correction i’ve made :

import random

n = int(input("How many exercises?"))
wrong = 0
abort = False
for k in range(n):
    a = random.randint(2, 13)
    b = random.randint(2, 13)
    help = str(k+1) + ". " + str(a) + " * " + str(b)
    answer = input(help + "=> ")
    if answer == "":
      abort = True
      break
    if answer != str(a * b):
      print("Wrong!")
      wrong += 1
    if abort == True:
      print("Noob")
if wrong == 0:
    print("Good")

'''Don't know what you wanted to do here
else:
  print("Hale" ,vigu)'''

2

solved Where’s the mistake in my Python program? [closed]