-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcalculator.py
More file actions
40 lines (28 loc) · 873 Bytes
/
Copy pathcalculator.py
File metadata and controls
40 lines (28 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Calculator module for demo."""
import sqlite3
def add(a: int, b: int) -> int:
return int(a) + int(b)
def divide(a: float, b: float) -> float:
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
def get_user_score(db_path: str, username: str) -> int | None:
with sqlite3.connect(db_path) as conn:
cursor = conn.cursor()
result = cursor.execute(
"SELECT score FROM users WHERE username = ?",
(username,),
).fetchone()
return result[0] if result else None
def subtract(a: int, b: int) -> int:
return a - b
def multiply(a: int, b: int) -> int:
return a * b
def process_scores(scores: list[int]) -> dict:
if not scores:
return {}
return {
"total": sum(scores),
"average": sum(scores) / len(scores),
"max": max(scores),
}