first commit

This commit is contained in:
Casper 2024-12-09 18:57:08 +01:00
commit 8b3f69ca74
8 changed files with 133 additions and 0 deletions

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,21 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="HtmlUnknownTag" enabled="true" level="WARNING" enabled_by_default="true">
<option name="myValues">
<value>
<list size="7">
<item index="0" class="java.lang.String" itemvalue="nobr" />
<item index="1" class="java.lang.String" itemvalue="noembed" />
<item index="2" class="java.lang.String" itemvalue="comment" />
<item index="3" class="java.lang.String" itemvalue="noscript" />
<item index="4" class="java.lang.String" itemvalue="embed" />
<item index="5" class="java.lang.String" itemvalue="script" />
<item index="6" class="java.lang.String" itemvalue="turbo-frame" />
</list>
</value>
</option>
<option name="myCustomValuesEnabled" value="true" />
</inspection_tool>
</profile>
</component>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

10
.idea/mathematics.iml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.9 (mathematics)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (mathematics)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/mathematics.iml" filepath="$PROJECT_DIR$/.idea/mathematics.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

72
main.py Normal file
View File

@ -0,0 +1,72 @@
import random
from colorama import Fore, Style
def generate_arithmetic_question(max_digits=2, num_terms=2, operation=None):
"""
Generates an arithmetic question based on the configured digits, number of terms, and operation.
Ensures all results are positive.
"""
if operation is None:
operation = random.choice(["add", "sub"]) # Randomly choose addition or subtraction
terms = [random.randint(10 ** (max_digits - 1), 10 ** max_digits - 1) for _ in range(num_terms)]
if operation == "add":
question = " + ".join(map(str, terms))
correct_answer = sum(terms)
elif operation == "sub":
terms.sort(reverse=True) # Ensure subtraction produces a positive result
question = " - ".join(map(str, terms))
correct_answer = terms[0]
for term in terms[1:]:
correct_answer -= term
return f"{question} =", correct_answer
def quiz(max_digits=2, num_terms=2, operation=None):
"""
Arithmetic practice quiz.
Configurables:
- max_digits: Maximum digits for each term in the problem.
- num_terms: Number of terms in the arithmetic problem.
- operation: 'add', 'sub', or None for random.
"""
print(f"Welcome to the Arithmetic Practice Quiz!")
total_questions = int(input("How many questions would you like to solve? "))
print(f"Operation mode: {operation.upper() if operation else 'RANDOM'}")
correct_count = 0
for question_num in range(1, total_questions + 1):
question, correct_answer = generate_arithmetic_question(max_digits, num_terms, operation)
print(f"Question {question_num}/{total_questions}: {question}")
attempt = 0
while attempt < 2:
try:
user_answer = int(input("Your answer: "))
if user_answer == correct_answer:
print(Fore.GREEN + "Correct!" + Style.RESET_ALL)
correct_count += 1
break
else:
attempt += 1
if attempt < 2:
print(Fore.YELLOW + "Wrong! Try again." + Style.RESET_ALL)
else:
print(Fore.RED + f"Wrong! The correct answer is {correct_answer}" + Style.RESET_ALL)
except ValueError:
print(Fore.RED + "Please enter a valid number." + Style.RESET_ALL)
print(f"\nYou got {correct_count}/{total_questions} correct. Thanks for playing!")
# Run the quiz
if __name__ == "__main__":
# Adjust default parameters if needed
quiz(
max_digits=2, # Max digits per term
num_terms=2, # Number of terms in the problem
operation=None # Operation: 'add', 'sub', or None for random
)