Skip to content

Commit cb218c7

Browse files
authored
Merge branch 'geekcomputers:master' into mr-temp
2 parents b19f69e + 2bea944 commit cb218c7

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

Sum of digits of a number.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,27 @@ def get_integer():
2424

2525

2626
def addition(num):
27+
"""
28+
Returns the sum of the digits of a number.
29+
Negative numbers are handled using the absolute value.
30+
31+
Examples:
32+
>>> addition(123)
33+
6
34+
>>> addition(-784)
35+
19
36+
"""
2737
Sum = 0
2838
if type(num) is type(
2939
None
3040
): # Checks if number type is none or not. If type is none program exits.
3141
print("Try again!")
3242
sys.exit()
43+
num = abs(num) # Handle negative numbers
3344
while num > 0: # Addition- adding the digits in the number.
3445
digit = int(num % 10)
3546
Sum += digit
36-
num /= 10
47+
num //= 10
3748
return Sum # Returns sum to where the function is called.
3849

3950

@@ -42,4 +53,5 @@ def addition(num):
4253
): # this is used to overcome the problems while importing this file.
4354
number = get_integer()
4455
Sum = addition(number)
45-
print(f"Sum of digits of {number} is {Sum}") # Prints the sum
56+
abs_display = f" (absolute value: {abs(number)})" if number < 0 else ""
57+
print(f"Sum of digits of {number}{abs_display} is {Sum}") # Prints the sum

length.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# User inputs the string and it gets stored in variable str
2-
str = input("Enter a string: ")
2+
str = input("Enter a string for str leangth : ")
33

44
# counter variable to count the character in a string
55
counter = 0

requirements_with_versions.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Tubes==0.2.1
1010
modules==1.0.0
1111
pdf2docx==0.5.8
1212
pong==1.5
13-
beautifulsoup4==4.14.2
13+
beautifulsoup4==4.14.3
1414
dictator==0.3.1
1515
caller==0.0.2
1616
watchdog==6.0.0
@@ -21,14 +21,14 @@ backend==0.2.4.1
2121
win10toast==0.9
2222
Counter==1.0.0
2323
Flask==3.1.2
24-
selenium==4.38.0
24+
selenium==4.39.0
2525
firebase-admin==7.1.0
2626
ujson==5.10.0
2727
requests==2.32.5
2828
quo==2023.5.1
2929
PyPDF2==3.0.1
3030
pyserial==3.5
31-
twilio==9.8.5
31+
twilio==9.8.8
3232
tabula==1.0.5
3333
nltk==3.9.2
3434
Pillow==12.0.0
@@ -37,26 +37,26 @@ xlrd==2.0.2
3737
fpdf==1.7.2
3838
mysql-connector-repackaged==0.3.1
3939
word2number==1.1
40-
tornado==6.5.2
40+
tornado==6.5.3
4141
obs==0.0.0
4242
todo==0.1
4343
oauth2client==4.1.3
4444
keras==3.12.0
45-
pymongo==4.15.4
45+
pymongo==4.15.5
4646
playsound==1.3.0
4747
pyttsx3==2.99
4848
auto-mix-prep==0.2.0
4949
lib==4.0.0
5050
pywifi==1.1.12
5151
patterns==0.3
52-
openai==2.8.1
52+
openai==2.9.0
5353
background==0.2.1
54-
pydantic==2.12.4
54+
pydantic==2.12.5
5555
openpyxl==3.1.2
5656
pytesseract==0.3.13
5757
requests-mock==1.12.1
5858
pyglet==2.1.11
59-
urllib3==2.5.0
59+
urllib3==2.6.2
6060
thirdai==0.9.33
6161
google-api-python-client==2.187.0
6262
sound==0.1.0
@@ -81,12 +81,12 @@ Unidecode==1.4.0
8181
Ball==0.2.9
8282
pynput==1.8.1
8383
gTTS==2.5.4
84-
ccxt==4.5.22
84+
ccxt==4.5.27
8585
fitz==0.0.1.dev2
86-
fastapi==0.122.0
87-
Django==5.2.7
86+
fastapi==0.124.4
87+
Django==6.0
8888
docx==0.2.4
89-
matplotlib==3.10.7
89+
matplotlib==3.10.8
9090
pyshorteners==1.0.1
9191
geocoder==1.38.1
9292
APScheduler==3.11.1
@@ -97,15 +97,15 @@ newspaper==0.1.0.7
9797
opencv-python==4.12.0.88
9898
tensorflow==2.20.0
9999
pandas==2.3.3
100-
pytest==8.4.2
100+
pytest==9.0.2
101101
qrcode==8.2
102102
googletrans==4.0.2
103103
slab==1.8.2
104104
psutil==7.1.3
105105
mediapipe==0.10.21
106106
rich==14.2.0
107107
httplib2==0.31.0
108-
protobuf==6.33.1
108+
protobuf==6.33.2
109109
colorama==0.4.6
110110
plyer==2.1.0
111111
Flask-Ask==0.9.8

sum_of_digits_of_a_number.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
0
1414
>>> sum_of_digits(999)
1515
27
16+
>>> sum_of_digits(-123)
17+
6
1618
"""
1719

1820
import sys
@@ -49,8 +51,8 @@ def sum_of_digits(n: int) -> int:
4951
Compute the sum of the digits of an integer.
5052
5153
Args:
52-
n:Non-negative integer
53-
If the integer is negative , it is converted to postive interger and assigned to same number
54+
n: Non-negative integer.
55+
If the integer is negative, it is converted to positive before computing the sum.
5456
5557
Returns:
5658
Sum of digits of the number.
@@ -60,8 +62,10 @@ def sum_of_digits(n: int) -> int:
6062
6
6163
>>> sum_of_digits(405)
6264
9
65+
>>> sum_of_digits(-789)
66+
24
6367
"""
64-
n=abs(n)
68+
n = abs(n) # FIX: handle negative numbers
6569
total = 0
6670
while n > 0:
6771
# Add last digit and remove it from n

0 commit comments

Comments
 (0)