Created
June 10, 2022 10:26
-
-
Save tusqasi/c61a24d32b05f17a04cbb1060a3f0fe2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# question 1 | |
from random import randint, seed | |
def disp_fraction(f: list): | |
return f"{' ' if f[0] == 0 else f[0]} {f[1]}/{f[2]}" | |
def main(ans: tuple[int, int, int]): | |
opts = [] | |
print(f"options are:") | |
for i in range(1, 5): | |
tmp = list(ans) | |
tmp[randint(0, 2)] = randint(1, 9) | |
## Check if a random option is correct answer | |
if opts and opts[~0] == ans: | |
tmp[randint(0, 2)] = randint(1, 9) | |
## Put the correction answer in a random spot | |
if i == randint(1, 5): | |
tmp = list(ans) | |
opts.append(tmp) | |
print(f"{i}) {disp_fraction(tmp)}") | |
if __name__ == "__main__": | |
## [ans] variable will be the correct answer to the question and it will print out options for that ans | |
## Fraction = [integer, numerator, denominator] | |
## a single question will have a question string and correct answer | |
questions = [ | |
{ | |
"question": "Convert the given fraction into mixed fraction - 22/7", | |
"ans": (3, 1, 7), | |
}, | |
{ | |
"question": "Write an equivalent fraction of 9/15", | |
"ans": (0, 18, 30), | |
}, | |
{ | |
"question": "Find the value of 3 4/7 ÷ 7", | |
"ans": (0, 18, 30), | |
}, | |
] | |
for i in questions: | |
print(i["question"]) | |
main(i["ans"]) | |
print("-" * 10) | |
""" | |
SAMPLE OUTPUPT: | |
>>> | |
Convert the given fraction into mixed fraction - 22/7 | |
options are: | |
1) 3 1/7 | |
2) 3 1/7 | |
3) 3 6/7 | |
4) 3 1/6 | |
---------- | |
Write an equivalent fraction of 9/15 | |
options are: | |
1) 18/3 | |
2) 2/30 | |
3) 4/30 | |
4) 18/30 | |
---------- | |
Find the value of 3 4/7 ÷ 7 | |
options are: | |
1) 5/30 | |
2) 18/4 | |
3) 18/30 | |
4) 1 18/30 | |
---------- | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment