Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3a53ffc

Browse files
author
Amogh Singhal
authored
Create has_only_digits.py
1 parent 595c7f0 commit 3a53ffc

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎has_only_digits.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Given a string, check if it only contains digits
2+
3+
def is_digit(input_str):
4+
digits = dict()
5+
6+
for char in input_str:
7+
if char in digits:
8+
digits[char] += 1
9+
else:
10+
digits[char] = 1
11+
12+
if sum(digits.values()) == len(input_str):
13+
return True
14+
else:
15+
return False
16+
17+
result = is_digit("095357973590759530")
18+
print(result) # True

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /