-
Notifications
You must be signed in to change notification settings - Fork 22
Тупикова Екатерина Викторовна, Б42 #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
66c5d9c
09f5251
d56e44d
eaf7892
df32941
74a65eb
67c3e12
a0126f4
cd5deb5
23a19c6
c571a76
b4d53d1
0ebc0c9
9f44e02
845307e
1023a77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,4 @@ jobs: | |
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: astral-sh/ruff-action@v3 | ||
| - run: ruff check . | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 3.12.2 |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| def binSearch(xs: list[int], x: int): | ||
| def bin_search(xs: list[int], x: int): | ||
|
|
||
| if type(x) != int: | ||
| raise "x is not int" | ||
|
|
||
| left, right = 0, len(xs) - 1 | ||
| while left < right: | ||
| while left <= right: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Нет теста на этот случай. |
||
| mid = (left + right) // 2 | ||
| if xs[mid] == x: | ||
| return mid | ||
|
|
@@ -9,3 +13,4 @@ def binSearch(xs: list[int], x: int): | |
| else: | ||
| right = mid - 1 | ||
| return -1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,37 @@ def modulo11Checksum(ISBNNumber: str): | |
|
|
||
| digits = [int(char) for char in ISBNNumber if char.isdigit()] | ||
|
|
||
| checkDigit = digits[-1] | ||
| assert (len(digits) == 9 and ISBNNumber[-1] == "X") or len(digits) == 10, "invalid lenght" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Валидация на |
||
|
|
||
| if (ISBNNumber[-1] == "X"): | ||
| #trash number | ||
| digits += [-1] | ||
| checkDigit = 10 | ||
| else: | ||
| checkDigit = digits[-1] | ||
|
|
||
| total = 0 | ||
| for i in range(len(digits) - 1): | ||
| weight = 10 | ||
| weight = 10 - i | ||
| digit = digits[i] | ||
| total += digit * weight | ||
|
|
||
| checksum = total + checkDigit | ||
| return checksum % 11 == 0 | ||
|
|
||
| if __name__ == "__main__": | ||
| while True: | ||
| isbn = input("Enter number: ") | ||
|
|
||
| if isbn == "-1": | ||
| break | ||
|
|
||
| try: | ||
| result = modulo11Checksum(isbn) | ||
| if result: | ||
| print("correct") | ||
| else: | ||
| print("incorrect") | ||
| except Exception as e: | ||
| print(f"{type(e).__name__}: {e}") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,22 @@ | ||
| from src.bin_search import binSearch | ||
| from src.bin_search import bin_search | ||
|
|
||
|
|
||
| def test_middle(): | ||
| assert binSearch([1, 2, 3, 4, 5], 4) == 3 | ||
| assert bin_search([1, 2, 3, 4, 5], 4) == 3 | ||
|
|
||
|
|
||
| def test_start(): | ||
| assert binSearch([1, 2, 3, 4], 2) == 1 | ||
| assert bin_search([1, 2, 3, 4], 2) == 1 | ||
|
|
||
|
|
||
| def test_not_in_list(): | ||
| assert binSearch([1, 2, 3, 4], 5) == -1 | ||
| assert bin_search([1, 2, 3, 4], 5) == -1 | ||
|
|
||
|
|
||
| def test_binary_lenght_middle_left(): | ||
| assert bin_search([1, 2, 3, 4, 5, 6, 7, 8], 4) == 3 | ||
|
|
||
|
|
||
| def test_binary_lenght_middle_right(): | ||
| assert bin_search([1, 2, 3, 4, 5, 6, 7, 8], 5) == 4 | ||
|
|
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Хотелось бы еще тесты с |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В Python 3.x мы уже не можем кидать строки как исключения.