Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions FileHandling/word,char,line,space_count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

import os

def counter(fname):
num_words = 0
num_lines = 0
num_charc = 0
num_spaces = 0
with open(fname, 'r') as f:
for line in f:

line = line.strip(os.linesep)
wordslist = line.split()

num_lines = num_lines + 1
num_words = num_words + len(wordslist)

num_charc = num_charc + sum(1 for c in line
if c not in (os.linesep, ' '))

num_spaces = num_spaces + sum(1 for s in line
if s in (os.linesep, ' '))


print("Number of words in text file: ", num_words)


print("Number of lines in text file: ", num_lines)


print("Number of characters in text file: ", num_charc)


print("Number of spaces in text file: ", num_spaces)


if __name__ == '__main__':
fname = input("enter file name")
try:
counter(fname)
except:
print('File not found')
20 changes: 12 additions & 8 deletions String/isPalindrome.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
def isPalindrome(word):
for i in range(0, int((len(word)/2))):
if(word[i] != word[(len(word)-1)-i]):
return False
return True

print(isPalindrome("ABBA"))
print(isPalindrome("Foo"))


def isPalindrome(s):
return s == s[::-1]

s = input("Enter word : ")
ans = isPalindrome(s)

if ans:
print("Yes")
else:
print("No")