-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from NipunRautela/nipunrautela
Added some algos in Python Algos Folder
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
def is_prime(num: int) -> bool: | ||
""" | ||
Returns True if the num is prime else false | ||
""" | ||
for i in range(2, num/2): | ||
if num%i == 0: | ||
return False | ||
|
||
return True | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
n = int(input("Enter the number of rows: ")) | ||
|
||
for i in range(1, n+1): | ||
for j in range(1, i+1): | ||
print(j, end="") | ||
print() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
def reverse_individual_words(input_str: str) -> str: | ||
""" | ||
Reverses words in a given string | ||
>>> reverse_individual_words("This is a text") | ||
'sihT si a txet' | ||
>>> reverse_individual_words("Another 1234 text") | ||
'rehtonA 4321 txet' | ||
>>> reverse_individual_words("A sentence with full stop.") | ||
'A ecnetnes htiw lluf pots.' | ||
""" | ||
individual_reverse_string = [] | ||
for word in input_str.split(" "): | ||
if word[-1] in [".", "!", "?"]: | ||
individual_reverse_string.append(word[-2::-1] + word[-1]) | ||
else: | ||
individual_reverse_string.append(word[::-1]) | ||
|
||
return " ".join(individual_reverse_string) | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() |