diff --git a/FileHandling/word,char,line,space_count.py b/FileHandling/word,char,line,space_count.py new file mode 100644 index 0000000..439f0ee --- /dev/null +++ b/FileHandling/word,char,line,space_count.py @@ -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') diff --git a/String/isPalindrome.py b/String/isPalindrome.py index 72e2d1c..676f4e4 100644 --- a/String/isPalindrome.py +++ b/String/isPalindrome.py @@ -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")) \ No newline at end of file + + +def isPalindrome(s): + return s == s[::-1] + +s = input("Enter word : ") +ans = isPalindrome(s) + +if ans: + print("Yes") +else: + print("No")