I am trying to make a program which asks the user if a (random generated number) is divisible by a number from 1 to 12 (also random generated).
from random import randint
def questionnaire_for_divisibility(): # call a function named questionnaire
count_timer = 0 # set counter to zero
count_limit = 10 # limit is 10.
count_wrong = 0 # We will count how many wrong questions the user did
count_right = 0 # We will count how many right questions the user did
while count_timer < count_limit: # while count is less than count_limit:
random_number = randint(0, 1 * 10 ** 6) # generate a random number from 1 to a million
random_divisibility_number = randint(1, 12) # generate a random number from 1 to 12. This is the divisor.
question_to_user = input(f"Is {random_number} divisible with {random_divisibility_number}?: ") # ask the
# user if the random generated number is divisible by the divisor (we want integers, not floats.)
x = random_number % random_divisibility_number # let x be the value of the remainder of random number
# divided by divisor
count_timer += 1 # count increments by one each run.
if random_number % random_divisibility_number == 0: # if the random number divided by the divisor = 0
# (no remainder) :
if question_to_user == "Yes" or "yes": # if the user says that the random number is divisible by the
# divisor
print("Correct!") # print "Correct!"
count_right += 1 # increase the count right by one each time the user gets the question right
elif question_to_user == "No" or "no": # else if the user says that the random number is not divisible by
# the divisor even though it is:
print("Wrong!") # print out "Wrong!"
count_wrong += 1 # increase the count wrong by one each time the user gets the question wrong.
elif random_number % random_divisibility_number == x >= 1: # if the remainder is greater than or equals to 1:
if question_to_user == "No" or "no": # If the user said that it is not divisible without giving a
# remainder and that is True:
print("Correct!") # print out "Correct!"
count_right += 1 # increase the count right by one each time the user gets the question right.
elif question_to_user == "Yes" or "yes": # else if the user said that it is divisible even though it's not:
print("Wrong") # print out "Wrong!"
count_wrong += 1 # # increase the count wrong by one each time the user gets the question wrong.
if count_timer == count_limit: # When the timer equals to the timer limit
print(f"Amount of right answered questions: {count_right}. ") # print the amount of right answered.
if count_right >= (1 / 2 * count_limit): # if the user got more than half the questions right
print("Awesome work!") # praise the user.
print(f"Amount of wrong answered questions: {count_wrong}") # print the amount of wrong answered.
if count_wrong >= (80 / 100 * count_limit): # if the amount of wrong answered questions is >= than 80%
print("Do a little better next time, okay buddy? I believe in you!") # Give a motivational comment
p = input("Would you like to see your results in percentage form?: ")
if p == "Yes":
print(f"Amount of right answered questions (in percentage): {(count_right / 10) * 100} %")
print(f"Amount of wrong answered questions (in percentage): {(count_wrong / 10) * 100} %")
print("Take an eye break now") # print that the user should take an eye break.
questionnaire_for_divisibility()
At the end of my program though, sometimes it says that a number is divisible by a divisor even though it is False. My program seems to be working, and I have tried to find ways to fix it, but to no prevail.
Could someone please help me?