Skip to content

Commit

Permalink
Added a folder called Python Algos for ALgorithms in Python language.…
Browse files Browse the repository at this point in the history
… Added some algos to the folder
  • Loading branch information
nipunrautela committed Oct 12, 2020
1 parent c65698e commit 078e64e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Python Algos/is_prime.py
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()
7 changes: 7 additions & 0 deletions Python Algos/pyramid.py
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()

24 changes: 24 additions & 0 deletions Python Algos/reverse_individual_words.py
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()

0 comments on commit 078e64e

Please sign in to comment.