Complete assesment 3
This commit is contained in:
parent
53ea335f9e
commit
6f660119f9
12
Practice Assignment 3/French_English.txt
Normal file
12
Practice Assignment 3/French_English.txt
Normal file
@ -0,0 +1,12 @@
|
||||
hello,bonjour
|
||||
apple,pomme
|
||||
cat,chat
|
||||
dog,chien
|
||||
book,livre
|
||||
house,maison
|
||||
water,eau
|
||||
car,voiture
|
||||
red,rouge
|
||||
thank you,merci
|
||||
goodbye,au revoir
|
||||
computer,ordinateur
|
||||
72
Practice Assignment 3/main.py
Normal file
72
Practice Assignment 3/main.py
Normal file
@ -0,0 +1,72 @@
|
||||
import random
|
||||
import os
|
||||
|
||||
def load_vocabulary(filepath):
|
||||
vocab = {}
|
||||
try:
|
||||
with open(filepath, 'r') as file:
|
||||
for line in file:
|
||||
eng, fra = line.strip().split(',')
|
||||
vocab[eng] = fra
|
||||
except FileNotFoundError:
|
||||
print("Error: The French_English data file could not be found.")
|
||||
except ValueError:
|
||||
print("Error: File data is malformed. Ensure 'English,French' format.")
|
||||
return vocab
|
||||
|
||||
def get_valid_student():
|
||||
name = input("Enter student name: ")
|
||||
while True:
|
||||
try:
|
||||
candidate_num = int(input("Enter candidate number (0001-9999): "))
|
||||
if 1 <= candidate_num <= 9999:
|
||||
return name, f"{candidate_num:04d}"
|
||||
print("Invalid range. Number must be between 0001 and 9999.")
|
||||
except ValueError:
|
||||
print("Invalid input type. Please enter a numerical value.")
|
||||
|
||||
def main():
|
||||
vocab = load_vocabulary("French_English.txt")
|
||||
if not vocab: return
|
||||
|
||||
name, cand_num = get_valid_student()
|
||||
correct_words = set()
|
||||
score_history = []
|
||||
|
||||
while True:
|
||||
available = [w for w in vocab.keys() if w not in correct_words]
|
||||
if len(available) < 10:
|
||||
print("Not enough new words left for a full 10-question quiz.")
|
||||
break
|
||||
|
||||
questions = random.sample(available, 10)
|
||||
current_score = 0
|
||||
|
||||
for word in questions:
|
||||
answer = input(f"What is the French translation for '{word}'? ")
|
||||
if answer.strip().lower() == vocab[word].lower():
|
||||
print("Correct!")
|
||||
current_score += 1
|
||||
correct_words.add(word)
|
||||
else:
|
||||
print(f"Incorrect. The correct spelling is '{vocab[word]}'.")
|
||||
|
||||
score_history.append(current_score)
|
||||
attempts = len(score_history)
|
||||
print(f"\nAttempt {attempts} finished. You scored {current_score} out of 10.")
|
||||
|
||||
try:
|
||||
with open("student_results.txt", "a") as results_file:
|
||||
results_file.write(f"{name},{cand_num},Attempt_{attempts},{current_score}/10\n")
|
||||
except IOError:
|
||||
print("Error: Could not save results to file.")
|
||||
|
||||
if attempts >= 2:
|
||||
average = sum(score_history) / attempts
|
||||
print(f"Average score after {attempts} attempts: {average:.2f}/10")
|
||||
|
||||
if input("\nWould you like to try another attempt? (y/n): ").lower() != 'y':
|
||||
break
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
1
Practice Assignment 3/student_results.txt
Normal file
1
Practice Assignment 3/student_results.txt
Normal file
@ -0,0 +1 @@
|
||||
Uthman,0331,Attempt_1,1/10
|
||||
@ -1 +0,0 @@
|
||||
3.14
|
||||
17
test/main.py
17
test/main.py
@ -1,17 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import typer
|
||||
from typing import Annotated
|
||||
|
||||
app = typer.Typer()
|
||||
|
||||
@app.command()
|
||||
def goodbye(name: Annotated[str, typer.Option(prompt="What is your name?")] = "World"):
|
||||
typer.echo(f"goodbye {name}")
|
||||
|
||||
@app.command()
|
||||
def main():
|
||||
typer.echo(f"Hello")
|
||||
|
||||
if __name__ == "__main__":
|
||||
app()
|
||||
@ -1,19 +0,0 @@
|
||||
[project]
|
||||
name = "test"
|
||||
version = "0.1.0"
|
||||
description = "Add your description here"
|
||||
readme = "README.md"
|
||||
authors = [
|
||||
{ name = "Uthman Fatih", email = "kingvcheese@gmail.com" }
|
||||
]
|
||||
requires-python = ">=3.14"
|
||||
dependencies = [
|
||||
"typer>=0.27.2",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
test = "test:main"
|
||||
|
||||
[build-system]
|
||||
requires = ["uv_build>=0.12.7,<0.13.0"]
|
||||
build-backend = "uv_build"
|
||||
@ -1,2 +0,0 @@
|
||||
def main() -> None:
|
||||
print("Hello from test!")
|
||||
99
test/uv.lock
generated
99
test/uv.lock
generated
@ -1,99 +0,0 @@
|
||||
version = 1
|
||||
revision = 3
|
||||
requires-python = ">=3.14"
|
||||
|
||||
[[package]]
|
||||
name = "annotated-doc"
|
||||
version = "0.0.5"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/5a/8e/38aa427ed5402449e226975b649c5dc73ccadfefeb95e6aecb8f8ea4b6b6/annotated_doc-0.0.5.tar.gz", hash = "sha256:c7e58ce09192557605d8bbd92836d7e1d520ac9580096042c0bfd197efacf1bb", size = 10758, upload-time = "2026-07-28T13:50:58.129Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/3e/30/e900b21425a860e195f32e37657aa1f7c7f2b1bfb26f03ca209b90933c06/annotated_doc-0.0.5-py3-none-any.whl", hash = "sha256:117bac03a25ede5df5440e855b32d556049ca169ead221505badf432fed4b101", size = 5302, upload-time = "2026-07-28T13:50:57.239Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "colorama"
|
||||
version = "0.4.6"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "markdown-it-py"
|
||||
version = "4.2.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "mdurl" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/06/ff/7841249c247aa650a76b9ee4bbaeae59370dc8bfd2f6c01f3630c35eb134/markdown_it_py-4.2.0.tar.gz", hash = "sha256:04a21681d6fbb623de53f6f364d352309d4094dd4194040a10fd51833e418d49", size = 82454, upload-time = "2026-05-07T12:08:28.36Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/b3/81/4da04ced5a082363ecfa159c010d200ecbd959ae410c10c0264a38cac0f5/markdown_it_py-4.2.0-py3-none-any.whl", hash = "sha256:9f7ebbcd14fe59494226453aed97c1070d83f8d24b6fc3a3bcf9a38092641c4a", size = 91687, upload-time = "2026-05-07T12:08:27.182Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mdurl"
|
||||
version = "0.1.2"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/d6/54/cfe61301667036ec958cb99bd3efefba235e65cdeb9c84d24a8293ba1d90/mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba", size = 8729, upload-time = "2022-08-14T12:40:10.846Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/b3/38/89ba8ad64ae25be8de66a6d463314cf1eb366222074cfda9ee839c56a4b4/mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8", size = 9979, upload-time = "2022-08-14T12:40:09.779Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pygments"
|
||||
version = "2.21.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/49/2e/ced460408999b33da6b31b0021b0f37d329e202d4169aeb164493778f25b/pygments-2.21.0.tar.gz", hash = "sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c", size = 5005329, upload-time = "2026-08-17T08:02:48.824Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/71/46/17f022dd3e953bf20a04a028a21ec746d942f8d2af30fa0f124fa0e6a684/pygments-2.21.0-py3-none-any.whl", hash = "sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9", size = 1250147, upload-time = "2026-08-17T08:02:44.912Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rich"
|
||||
version = "15.0.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "markdown-it-py" },
|
||||
{ name = "pygments" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/c0/8f/0722ca900cc807c13a6a0c696dacf35430f72e0ec571c4275d2371fca3e9/rich-15.0.0.tar.gz", hash = "sha256:edd07a4824c6b40189fb7ac9bc4c52536e9780fbbfbddf6f1e2502c31b068c36", size = 230680, upload-time = "2026-04-12T08:24:00.75Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/82/3b/64d4899d73f91ba49a8c18a8ff3f0ea8f1c1d75481760df8c68ef5235bf5/rich-15.0.0-py3-none-any.whl", hash = "sha256:33bd4ef74232fb73fe9279a257718407f169c09b78a87ad3d296f548e27de0bb", size = 310654, upload-time = "2026-04-12T08:24:02.83Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shellingham"
|
||||
version = "1.5.4"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/58/15/8b3609fd3830ef7b27b655beb4b4e9c62313a4e8da8c676e142cc210d58e/shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de", size = 10310, upload-time = "2023-10-24T04:13:40.426Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/e0/f9/0595336914c5619e5f28a1fb793285925a8cd4b432c9da0a987836c7f822/shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686", size = 9755, upload-time = "2023-10-24T04:13:38.866Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "test"
|
||||
version = "0.1.0"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "typer" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [{ name = "typer", specifier = ">=0.27.2" }]
|
||||
|
||||
[[package]]
|
||||
name = "typer"
|
||||
version = "0.27.2"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "annotated-doc" },
|
||||
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
||||
{ name = "rich" },
|
||||
{ name = "shellingham" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/16/f7/57713ba479fd405eb76de31404b2c744c289e336b2d999511ebf51e496f7/typer-0.27.2.tar.gz", hash = "sha256:269b7eb9d3c202ca84b4bc9618cb04ebb43d3d4d1e567e4c768607232c05f945", size = 204045, upload-time = "2026-08-28T10:26:55.046Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/dc/bf/205d0004930ede8f542fb58f601526fccf4ae7626075ca1e6c4de5d3d652/typer-0.27.2-py3-none-any.whl", hash = "sha256:b3a5fc4342d5fc8fda8fc3010b1cf117e9249aab7fae800c2eff62fd3842d97d", size = 123130, upload-time = "2026-08-28T10:26:53.752Z" },
|
||||
]
|
||||
Loading…
Reference in New Issue
Block a user