Skip to content

Commit cfc9b65

Browse files
committed
used black to perform code reformatting on all files
1 parent fcb8030 commit cfc9b65

File tree

250 files changed

+2894
-2370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+2894
-2370
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ print(lower+upper+odd+even)
2323

2424
# thumbnail cache on Windows
2525
Thumbs.db
26+
27+
__pycache__
28+
*.sqlite3

1 File handle/File handle binary/Update a binary file2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def update():
99
value = pickle.load(File)
1010
found = False
1111
roll = int(input("Enter the roll number of the record"))
12-
12+
1313
for i in value:
1414
if roll == i[0]:
1515
print(f"current name {i[1]}")

1 File handle/File handle binary/question 1 (elegible for remedial, top marks).py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
1010
"""
11+
1112
# also find no. of children who got top marks
1213

1314
import pickle

1 File handle/File handle text/counter.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
- Code readability
66
"""
77

8+
89
class Counter:
910

10-
def __init__(self, text:str) -> None:
11+
def __init__(self, text: str) -> None:
1112
self.text = text
1213

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

1819
def count(self) -> None:
19-
20+
2021
for char in self.text:
2122
if char.lower():
2223
self.count_lower += 1
2324
elif char.upper():
2425
self.count_upper += 1
2526

2627
return (self.count_lower, self.count_upper)
27-
28+
2829
def get_total_lower(self) -> int:
2930
return self.count_lower
3031

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

3435
def get_total(self) -> int:
35-
return self.count_lower + self.count_upper
36+
return self.count_lower + self.count_upper
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
21
import os
32
import time
4-
file_name= input("Enter the file name to create:- ")
3+
4+
file_name = input("Enter the file name to create:- ")
55

66
print(file_name)
77

8+
89
def write_to_file(file_name):
910

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

1617
while True:
1718
text = input("enter any text to add in the file:- ")
18-
F.write( f"{text}\n" )
19+
F.write(f"{text}\n")
1920
choice = input("Do you want to enter more, y/n").lower()
2021
if choice == "n":
2122
break
22-
23+
24+
2325
def longlines():
2426

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

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

37+
3538
if __name__ == "__main__":
3639
write_to_file(file_name)
3740
time.sleep(1)
38-
longlines()
41+
longlines()

1 File handle/File handle text/input,output and error streams.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44
sys.stdout.write("Enter the name of the file")
55
file = sys.stdin.readline()
66

7-
with open(file.strip(), ) as F:
7+
with open(
8+
file.strip(),
9+
) as F:
810

911
while True:
1012
ch = F.readlines()
11-
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
13+
for (
14+
i
15+
) in (
16+
ch
17+
): # ch is the whole file,for i in ch gives lines, for j in i gives letters,for j in i.split gives words
1218
print(i, end="")
1319
else:
1420
sys.stderr.write("End of file reached")
1521
break
16-

1 File handle/File handle text/question 2.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,32 @@
33
using read function
44
and display those words, which are less than 4 characters. """
55

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

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

99
def display_words(file_path):
1010

1111
try:
1212
with open(file_path) as F:
1313
words = F.read().split()
14-
words_less_than_40 = list( filter(lambda word: len(word) < 4, words) )
14+
words_less_than_40 = list(filter(lambda word: len(word) < 4, words))
1515

1616
for word in words_less_than_40:
1717
print(word)
18-
19-
return "The total number of the word's count which has less than 4 characters", (len(words_less_than_40))
20-
18+
19+
return (
20+
"The total number of the word's count which has less than 4 characters",
21+
(len(words_less_than_40)),
22+
)
23+
2124
except FileNotFoundError:
2225
print("File not found")
2326

27+
2428
print("Just need to pass the path of your file..")
2529

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

2832
if __name__ == "__main__":
29-
30-
print(display_words(file_path))
31-
32-
33-
34-
3533

34+
print(display_words(file_path))

1 File handle/File handle text/question 5.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,30 @@
44
import time, os
55
from counter import Counter
66

7-
print("You will see the count of lowercase, uppercase and total count of alphabets in provided file..")
7+
print(
8+
"You will see the count of lowercase, uppercase and total count of alphabets in provided file.."
9+
)
810

911

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

1214
if os.path.exists(file_path):
13-
print('The file exists and this is the path:\n',file_path)
15+
print("The file exists and this is the path:\n", file_path)
1416

1517

1618
def lowercase(file_path):
1719
try:
1820

1921
with open(file_path) as F:
2022
word_counter = Counter(F.read())
21-
22-
print(f"The total number of lower case letters are {word_counter.get_total_lower()}")
23+
24+
print(
25+
f"The total number of lower case letters are {word_counter.get_total_lower()}"
26+
)
2327
time.sleep(0.5)
24-
print(f"The total number of upper case letters are {word_counter.get_total_upper()}")
28+
print(
29+
f"The total number of upper case letters are {word_counter.get_total_upper()}"
30+
)
2531
time.sleep(0.5)
2632
print(f"The total number of letters are {word_counter.get_total()}")
2733
time.sleep(0.5)
@@ -30,8 +36,6 @@ def lowercase(file_path):
3036
print("File is not exist.. Please check AGAIN")
3137

3238

33-
34-
3539
if __name__ == "__main__":
3640

3741
lowercase(file_path)

1 File handle/File handle text/question 6.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33

44
from counter import Counter
55

6+
67
def lowercase():
78

89
with open("happy.txt") as F:
910
word_counter = Counter(F.read())
10-
11-
print(f"The total number of lower case letters are {word_counter.get_total_lower()}")
12-
print(f"The total number of upper case letters are {word_counter.get_total_upper()}")
11+
12+
print(
13+
f"The total number of lower case letters are {word_counter.get_total_lower()}"
14+
)
15+
print(
16+
f"The total number of upper case letters are {word_counter.get_total_upper()}"
17+
)
1318
print(f"The total number of letters are {word_counter.get_total()}")
1419

20+
1521
if __name__ == "__main__":
1622
lowercase()

1 File handle/File handle text/question3.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
import os
66
import time
7-
file_name= input("Enter the file name to create:- ")
7+
8+
file_name = input("Enter the file name to create:- ")
89

910
# step1:
1011
print(file_name)
1112

1213

13-
1414
def write_to_file(file_name):
1515

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

2222
while True:
2323
text = input("enter any text")
24-
F.write(f"{text}\n")
24+
F.write(f"{text}\n")
2525

2626
if input("do you want to enter more, y/n").lower() == "n":
2727
break
28-
28+
29+
2930
# step2:
3031
def check_first_letter():
3132
with open(file_name) as F:
@@ -37,10 +38,13 @@ def check_first_letter():
3738
count_i = first_letters.count("i")
3839
count_m = first_letters.count("m")
3940

40-
print(f"The total number of sentences starting with I or M are {count_i + count_m}")
41+
print(
42+
f"The total number of sentences starting with I or M are {count_i + count_m}"
43+
)
44+
4145

4246
if __name__ == "__main__":
43-
47+
4448
write_to_file(file_name)
4549
time.sleep(1)
4650
check_first_letter()

0 commit comments

Comments
 (0)