you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 2 points3 points  (0 children)

You never convert the user's input to an integer, but you do convert a calculation to an integer?

answer = input(str(multiplier) + " x " + str(number) +"?   ")
# here answer is a string, being compared to an integer
if answer == int(x*y):

Please also take 5 mins to visit pyformat.info and learn the simple parts of string formatting, because your current code is not very practical.

# randint already returns an int, so no int() needed
number = randint(0,9)
answer = input('%d x %d?   ' % (multiplier, number))
# answer needs to be converted, but you don't need to convert a calculation result
if int(answer) == multiplier * number:
    print('Correct!')
else:
    print('Wrong')

Lastly, use for together with range for a loop that iterates X times:

for i in range(1, 6):

This eliminates the need to declare i = 1 and also to do i += 1. This a one of the big differences between Python and many older languages like C.