Skip to content

Commit 20aa30f

Browse files
committed
Update grammar for python 3.13.5
1 parent 168daf8 commit 20aa30f

File tree

22 files changed

+1061
-489
lines changed

22 files changed

+1061
-489
lines changed

Automated Scheduled Call Reminders/caller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def search():
4141
for doc in list_of_docs:
4242
if doc["from"][0:5] == five_minutes_prior:
4343
phone_number = doc["phone"]
44-
call = client.calls.create(
44+
client.calls.create(
4545
to=phone_number,
4646
from_="add your twilio number",
4747
url="http://demo.twilio.com/docs/voice.xml",

CRC/crc.py

Lines changed: 83 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,94 @@
1-
def crc_check(data, div):
2-
l = len(div)
3-
ct = 0
4-
data = [int(i) for i in data]
5-
div = [int(i) for i in div]
6-
zero = [0 for i in range(l)]
7-
temp_data = [data[i] for i in range(l)]
8-
result = []
9-
for j in range(len(data) - len(div) + 1):
1+
from typing import List
2+
3+
def crc_check(data: str, div: str) -> List[int]:
4+
"""
5+
Perform CRC (Cyclic Redundancy Check) calculation.
6+
7+
Args:
8+
data: Input data string (binary digits)
9+
div: Divisor string (binary digits, typically a polynomial)
10+
11+
Returns:
12+
List of integers representing the CRC remainder
13+
"""
14+
divisor_length: int = len(div) # Renamed from 'l' to 'divisor_length'
15+
data_list: List[int] = [int(i) for i in data]
16+
div_list: List[int] = [int(i) for i in div]
17+
zero: List[int] = [0] * divisor_length
18+
temp_data: List[int] = data_list[:divisor_length]
19+
result: List[int] = []
20+
21+
for j in range(len(data_list) - divisor_length + 1):
1022
print("Temp_dividend", temp_data)
11-
msb = temp_data[0]
23+
msb: int = temp_data[0]
24+
1225
if msb == 0:
1326
result.append(0)
14-
for i in range(l - 1, -1, -1):
15-
temp_data[i] = temp_data[i] ^ zero[i]
27+
temp_data = [temp_data[i] ^ zero[i] for i in range(divisor_length-1, -1, -1)]
1628
else:
1729
result.append(1)
18-
for i in range(l - 1, -1, -1):
19-
temp_data[i] = temp_data[i] ^ div[i]
30+
temp_data = [temp_data[i] ^ div_list[i] for i in range(divisor_length-1, -1, -1)]
31+
2032
temp_data.pop(0)
21-
if l + j < len(data):
22-
temp_data.append(data[l + j])
23-
crc = temp_data
33+
if divisor_length + j < len(data_list):
34+
temp_data.append(data_list[divisor_length + j])
35+
36+
crc: List[int] = temp_data
2437
print("Quotient: ", result, "remainder", crc)
2538
return crc
2639

40+
def validate_binary_input(input_str: str) -> bool:
41+
"""Check if input string contains only 0s and 1s"""
42+
return all(c in {'0', '1'} for c in input_str)
2743

28-
# returning crc value
29-
44+
def main() -> None:
45+
"""Main program loop for CRC calculation and verification"""
46+
while True:
47+
try:
48+
# Get input from user
49+
data: str = input("Enter data: ").strip()
50+
if not validate_binary_input(data):
51+
raise ValueError("Data must be a binary string (0s and 1s)")
52+
53+
div: str = input("Enter divisor: ").strip()
54+
if not validate_binary_input(div):
55+
raise ValueError("Divisor must be a binary string (0s and 1s)")
56+
if len(div) < 2:
57+
raise ValueError("Divisor length must be at least 2")
58+
59+
original_data: str = data
60+
padded_data: str = data + "0" * (len(div) - 1)
61+
62+
# Calculate CRC
63+
crc: List[int] = crc_check(padded_data, div)
64+
crc_str: str = ''.join(str(c) for c in crc)
65+
66+
# Display sent data
67+
sent_data: str = original_data + crc_str
68+
print("Sent data: ", sent_data)
69+
70+
# Verify CRC at receiver side
71+
print("If again applying CRC algorithm, the remainder/CRC must be zero if errorless.")
72+
receiver_crc: List[int] = crc_check(sent_data, div)
73+
print("Receiver side remainder: ", receiver_crc)
74+
75+
# Check if remainder is zero
76+
if all(bit == 0 for bit in receiver_crc):
77+
print("CRC verification successful - no detected errors.")
78+
else:
79+
print("CRC verification failed - errors detected.")
80+
81+
except ValueError as ve:
82+
print(f"Input Error: {ve}")
83+
continue
84+
except Exception as e:
85+
print(f"An unexpected error occurred: {e}")
86+
continue
87+
88+
# Ask user to continue
89+
ch: str = input("Continue [Y/N]: ").strip().upper()
90+
if ch == "N":
91+
break
3092

31-
while 1 > 0:
32-
print("Enter data: ")
33-
data = input() # can use it like int(input())
34-
print("Enter divisor")
35-
div = input() # can use it like int(input())
36-
original_data = data
37-
data = data + ("0" * (len(div) - 1))
38-
crc = crc_check(data, div)
39-
crc_str = ""
40-
for c in crc:
41-
crc_str += c
42-
print("Sent data: ", original_data + crc_str)
43-
sent_data = original_data + crc_str
44-
print(
45-
"If again applying CRC algorithm, the remainder/CRC must be zero if errorless."
46-
)
47-
crc = crc_check(sent_data, div)
48-
remainder = crc
49-
print("Receiver side remainder: ", remainder)
50-
print("Continue [Y/N]:")
51-
ch = input()
52-
if ch == "N" or ch == "n":
53-
break
54-
else:
55-
continue
93+
if __name__ == "__main__":
94+
main()

Colors/multicoloredline.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22
from rich.syntax import Syntax
33
from rich.progress import Progress, SpinnerColumn, BarColumn, TextColumn
44
from rich.table import Table
5+
from typing import Dict, Any
56
import time
67
import json
78

8-
console = Console()
9+
console: Console = Console()
910

1011
# Fancy separator
1112
console.rule("[bold]Welcome to Rich Terminal[/bold]", style="rainbow")
1213

1314
# Define some JSON data
14-
json_data = {
15+
json_data: Dict[str, Any] = {
1516
"message": "Hello, World!",
1617
"status": "success",
1718
"code": 200
1819
}
1920

2021
# Print JSON with syntax highlighting
21-
syntax = Syntax(json.dumps(json_data, indent=4), "json", theme="monokai", line_numbers=True)
22+
syntax: Syntax = Syntax(json.dumps(json_data, indent=4), "json", theme="monokai", line_numbers=True)
2223
console.print(syntax)
2324

2425
# Simulating a progress bar
@@ -31,15 +32,15 @@
3132
TextColumn("{task.percentage:>3.0f}%"),
3233
console=console,
3334
) as progress:
34-
task = progress.add_task("[cyan]Loading...", total=100)
35+
task_id: int = progress.add_task("[cyan]Loading...", total=100)
3536
for _ in range(100):
3637
time.sleep(0.02)
37-
progress.update(task, advance=1)
38+
progress.update(task_id, advance=1)
3839

3940
# Create a rich table
4041
console.print("\n[bold magenta]Results Summary:[/bold magenta]\n")
4142

42-
table = Table(title="System Report", show_header=True, header_style="bold cyan")
43+
table: Table = Table(title="System Report", show_header=True, header_style="bold cyan")
4344
table.add_column("Metric", style="bold yellow")
4445
table.add_column("Value", justify="right", style="bold green")
4546

@@ -51,4 +52,4 @@
5152

5253
# Success message
5354
console.print("\n[bold green]🎉 Process completed successfully![/bold green]\n")
54-
console.rule(style="rainbow")
55+
console.rule(style="rainbow")

0 commit comments

Comments
 (0)