Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lint issue #2230

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ print(lower+upper+odd+even)

# thumbnail cache on Windows
Thumbs.db

__pycache__
*.sqlite3
2 changes: 1 addition & 1 deletion 1 File handle/File handle binary/Update a binary file2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def update():
value = pickle.load(File)
found = False
roll = int(input("Enter the roll number of the record"))

for i in value:
if roll == i[0]:
print(f"current name {i[1]}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


"""

# also find no. of children who got top marks

import pickle
Expand Down
9 changes: 5 additions & 4 deletions 1 File handle/File handle text/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
- Code readability
"""


class Counter:

def __init__(self, text:str) -> None:
def __init__(self, text: str) -> None:
self.text = text

# Define the initial count of the lower and upper case.
Expand All @@ -16,20 +17,20 @@ def __init__(self, text:str) -> None:
self.count()

def count(self) -> None:

for char in self.text:
if char.lower():
self.count_lower += 1
elif char.upper():
self.count_upper += 1

return (self.count_lower, self.count_upper)

def get_total_lower(self) -> int:
return self.count_lower

def get_total_upper(self) -> int:
return self.count_upper

def get_total(self) -> int:
return self.count_lower + self.count_upper
return self.count_lower + self.count_upper
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

import os
import time
file_name= input("Enter the file name to create:- ")

file_name = input("Enter the file name to create:- ")

print(file_name)


def write_to_file(file_name):

if os.path.exists(file_name):
Expand All @@ -15,24 +16,26 @@ def write_to_file(file_name):

while True:
text = input("enter any text to add in the file:- ")
F.write( f"{text}\n" )
F.write(f"{text}\n")
choice = input("Do you want to enter more, y/n").lower()
if choice == "n":
break



def longlines():

with open(file_name, encoding='utf-8') as F:
with open(file_name, encoding="utf-8") as F:
lines = F.readlines()
lines_less_than_50 = list( filter(lambda line: len(line) < 50, lines ) )
lines_less_than_50 = list(filter(lambda line: len(line) < 50, lines))

if not lines_less_than_50:
print("There is no line which is less than 50")
else:
for i in lines_less_than_50:
print(i, end="\t")


if __name__ == "__main__":
write_to_file(file_name)
time.sleep(1)
longlines()
longlines()
11 changes: 8 additions & 3 deletions 1 File handle/File handle text/input,output and error streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
sys.stdout.write("Enter the name of the file")
file = sys.stdin.readline()

with open(file.strip(), ) as F:
with open(
file.strip(),
) as F:

while True:
ch = F.readlines()
for (i) in ch: # ch is the whole file,for i in ch gives lines, for j in i gives letters,for j in i.split gives words
for (
i
) in (
ch
): # ch is the whole file,for i in ch gives lines, for j in i gives letters,for j in i.split gives words
print(i, end="")
else:
sys.stderr.write("End of file reached")
break

21 changes: 10 additions & 11 deletions 1 File handle/File handle text/question 2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,32 @@
using read function
and display those words, which are less than 4 characters. """

print("Hey!! You can print the word which are less then 4 characters")

print("Hey!! You can print the word which are less then 4 characters")

def display_words(file_path):

try:
with open(file_path) as F:
words = F.read().split()
words_less_than_40 = list( filter(lambda word: len(word) < 4, words) )
words_less_than_40 = list(filter(lambda word: len(word) < 4, words))

for word in words_less_than_40:
print(word)

return "The total number of the word's count which has less than 4 characters", (len(words_less_than_40))


return (
"The total number of the word's count which has less than 4 characters",
(len(words_less_than_40)),
)

except FileNotFoundError:
print("File not found")


print("Just need to pass the path of your file..")

file_path = input("Please, Enter file path: ")

if __name__ == "__main__":

print(display_words(file_path))





print(display_words(file_path))
18 changes: 11 additions & 7 deletions 1 File handle/File handle text/question 5.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@
import time, os
from counter import Counter

print("You will see the count of lowercase, uppercase and total count of alphabets in provided file..")
print(
"You will see the count of lowercase, uppercase and total count of alphabets in provided file.."
)


file_path = input("Please, Enter file path: ")

if os.path.exists(file_path):
print('The file exists and this is the path:\n',file_path)
print("The file exists and this is the path:\n", file_path)


def lowercase(file_path):
try:

with open(file_path) as F:
word_counter = Counter(F.read())

print(f"The total number of lower case letters are {word_counter.get_total_lower()}")

print(
f"The total number of lower case letters are {word_counter.get_total_lower()}"
)
time.sleep(0.5)
print(f"The total number of upper case letters are {word_counter.get_total_upper()}")
print(
f"The total number of upper case letters are {word_counter.get_total_upper()}"
)
time.sleep(0.5)
print(f"The total number of letters are {word_counter.get_total()}")
time.sleep(0.5)
Expand All @@ -30,8 +36,6 @@ def lowercase(file_path):
print("File is not exist.. Please check AGAIN")




if __name__ == "__main__":

lowercase(file_path)
12 changes: 9 additions & 3 deletions 1 File handle/File handle text/question 6.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@

from counter import Counter


def lowercase():

with open("happy.txt") as F:
word_counter = Counter(F.read())

print(f"The total number of lower case letters are {word_counter.get_total_lower()}")
print(f"The total number of upper case letters are {word_counter.get_total_upper()}")

print(
f"The total number of lower case letters are {word_counter.get_total_lower()}"
)
print(
f"The total number of upper case letters are {word_counter.get_total_upper()}"
)
print(f"The total number of letters are {word_counter.get_total()}")


if __name__ == "__main__":
lowercase()
16 changes: 10 additions & 6 deletions 1 File handle/File handle text/question3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

import os
import time
file_name= input("Enter the file name to create:- ")

file_name = input("Enter the file name to create:- ")

# step1:
print(file_name)



def write_to_file(file_name):

if os.path.exists(file_name):
Expand All @@ -21,11 +21,12 @@ def write_to_file(file_name):

while True:
text = input("enter any text")
F.write(f"{text}\n")
F.write(f"{text}\n")

if input("do you want to enter more, y/n").lower() == "n":
break



# step2:
def check_first_letter():
with open(file_name) as F:
Expand All @@ -37,10 +38,13 @@ def check_first_letter():
count_i = first_letters.count("i")
count_m = first_letters.count("m")

print(f"The total number of sentences starting with I or M are {count_i + count_m}")
print(
f"The total number of sentences starting with I or M are {count_i + count_m}"
)


if __name__ == "__main__":

write_to_file(file_name)
time.sleep(1)
check_first_letter()
Loading
Loading