Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 6b44ed9

Browse files
committed
Fix code style issues with Black
1 parent 3a38095 commit 6b44ed9

7 files changed

Lines changed: 96 additions & 64 deletions

File tree

projects/Calculator-GUI-With-Python/app.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,63 @@
44
from kivy.uix.gridlayout import GridLayout
55
from kivy.uix.label import Label
66

7+
78
class myApp(App):
89
def build(self):
9-
root_widget = BoxLayout(orientation='vertical')
10-
output_label = Label(size_hint_y = 0.75, font_size=50)
11-
button_symbols = ('1', '2', '3', '+',
12-
'4', '5', '6', '-',
13-
'7', '8', '9', '.',
14-
'0', '*', '/', '=')
10+
root_widget = BoxLayout(orientation="vertical")
11+
output_label = Label(size_hint_y=0.75, font_size=50)
12+
button_symbols = (
13+
"1",
14+
"2",
15+
"3",
16+
"+",
17+
"4",
18+
"5",
19+
"6",
20+
"-",
21+
"7",
22+
"8",
23+
"9",
24+
".",
25+
"0",
26+
"*",
27+
"/",
28+
"=",
29+
)
1530
button_grid = GridLayout(cols=4, size_hint_y=2)
1631
for symbol in button_symbols:
1732
button_grid.add_widget(Button(text=symbol))
1833

19-
clear_button = Button(text = 'Clear', size_hint_y=None, height=100)
34+
clear_button = Button(text="Clear", size_hint_y=None, height=100)
35+
2036
def print_button_text(instance):
2137
output_label.text += instance.text
38+
2239
for button in button_grid.children[1:]:
2340
button.bind(on_press=print_button_text)
41+
2442
def resize_label_text(label, new_height):
25-
label.fontsize = 0.5*label.height
43+
label.fontsize = 0.5 * label.height
44+
2645
output_label.bind(height=resize_label_text)
2746

2847
def evaluate_result(instance):
2948
try:
3049
output_label.text = str(eval(output_label.text))
3150
except SyntaxError:
32-
output_label.text = 'Python Syntax error!'
51+
output_label.text = "Python Syntax error!"
52+
3353
button_grid.children[0].bind(on_press=evaluate_result)
3454

3555
def clear_label(instance):
3656
output_label.text = " "
57+
3758
clear_button.bind(on_press=clear_label)
3859

3960
root_widget.add_widget(output_label)
4061
root_widget.add_widget(button_grid)
4162
root_widget.add_widget(clear_button)
4263
return root_widget
43-
myApp().run()
64+
65+
66+
myApp().run()

projects/Coin Flip/coinflip.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,35 @@
22
import os
33

44

5-
65
while True:
7-
global answer_y
6+
global answer_y
87

9-
#Clears the shell/terminal (where all the text is)
10-
os.system('clear')
8+
# Clears the shell/terminal (where all the text is)
9+
os.system("clear")
1110

12-
answer = input("Pick a side for the coin toss: ")
11+
answer = input("Pick a side for the coin toss: ")
1312

14-
list1 = ["heads", "tails"]
13+
list1 = ["heads", "tails"]
1514

16-
# Picks randonly from the list
17-
random_s = random.choice(list1)
18-
19-
print("You got... "+ random_s)
15+
# Picks randonly from the list
16+
random_s = random.choice(list1)
2017

21-
if answer.lower() == random_s:
22-
# Tells the user if they won
23-
print("Nice you won the coin toss!!")
18+
print("You got... " + random_s)
2419

25-
# Asks the user if they want to play again
26-
answer_y = input("Wanna play agian? ")
27-
if answer_y.lower() == "no":
28-
break
20+
if answer.lower() == random_s:
21+
# Tells the user if they won
22+
print("Nice you won the coin toss!!")
2923

30-
if answer.lower() != random_s:
31-
# Tells the user if they lost
32-
print("OOF.")
24+
# Asks the user if they want to play again
25+
answer_y = input("Wanna play agian? ")
26+
if answer_y.lower() == "no":
27+
break
3328

34-
# Asks the user if they want to play again
35-
answer_y = input("Wanna play agian? ")
36-
if answer_y.lower() == "no":
37-
break
38-
29+
if answer.lower() != random_s:
30+
# Tells the user if they lost
31+
print("OOF.")
3932

40-
33+
# Asks the user if they want to play again
34+
answer_y = input("Wanna play agian? ")
35+
if answer_y.lower() == "no":
36+
break

projects/Expense-Tracker/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def is_empty():
256256
else:
257257
print("The Database is not empty")
258258

259+
259260
# expense analysis function
260261
def analyse_expense():
261262
"""
@@ -281,6 +282,7 @@ def analyse_expense():
281282

282283
print("\n***END OF EXPENSE ANALYSIS***")
283284

285+
284286
def main_menu():
285287
# conn=db_init()
286288
while True:
@@ -316,7 +318,7 @@ def main_menu():
316318
is_empty()
317319
elif choice == "9":
318320
analyse_expense()
319-
elif choice=="10":
321+
elif choice == "10":
320322
exit(0)
321323
else:
322324
print("Invalid choice. Please try again.")

projects/Loan Calculator/main.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
def calculate_loan_payment(principal, annual_interest_rate, months):
22
# Convert annual interest rate to monthly rate
33
monthly_interest_rate = annual_interest_rate / 12 / 100
4-
4+
55
# Calculate monthly payment
66
if monthly_interest_rate == 0:
77
monthly_payment = principal / months
@@ -11,22 +11,26 @@ def calculate_loan_payment(principal, annual_interest_rate, months):
1111
* (monthly_interest_rate * (1 + monthly_interest_rate) ** months)
1212
/ ((1 + monthly_interest_rate) ** months - 1)
1313
)
14-
14+
1515
return monthly_payment
1616

17+
1718
def main():
1819
print("Welcome to the Loan Calculator!")
19-
20+
2021
# Get user input
2122
principal = float(input("Enter the loan amount: $"))
22-
annual_interest_rate = float(input("Enter the annual interest rate (as a percentage): "))
23+
annual_interest_rate = float(
24+
input("Enter the annual interest rate (as a percentage): ")
25+
)
2326
months = int(input("Enter the loan term (in months): "))
24-
27+
2528
# Calculate monthly payment
2629
monthly_payment = calculate_loan_payment(principal, annual_interest_rate, months)
27-
30+
2831
# Display the result
2932
print(f"Your monthly payment will be: ${monthly_payment:.2f}")
3033

34+
3135
if __name__ == "__main__":
3236
main()

projects/Medium Article Reader/main.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def speak(audio):
2121
engine.say(audio)
2222
engine.runAndWait()
2323

24+
2425
try:
2526
text = input("Paste article URL: ")
2627

@@ -32,21 +33,25 @@ def speak(audio):
3233
article = p.getText().strip()
3334
articles.append(article)
3435
txt = " ".join(articles)
35-
3636

3737
## loading text from URL for summarizing..
3838
loader = WebBaseLoader(text)
3939
docs = loader.load()
40-
llm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo-16k",openai_api_key=openai.openai_api_key)
40+
llm = ChatOpenAI(
41+
temperature=0,
42+
model_name="gpt-3.5-turbo-16k",
43+
openai_api_key=openai.openai_api_key,
44+
)
4145
chain = load_summarize_chain(llm, chain_type="stuff")
4246
print(chain.run(docs))
4347

44-
45-
user_choice=int(input("Enter 1 for summary of article or Enter 2 for whole article: "))
46-
if(user_choice==1):
48+
user_choice = int(
49+
input("Enter 1 for summary of article or Enter 2 for whole article: ")
50+
)
51+
if user_choice == 1:
4752
speak(chain.run(docs))
4853
else:
4954
speak(txt)
5055

5156
except requests.exceptions.RequestException as e:
52-
print(f"An error occurred: {e}")
57+
print(f"An error occurred: {e}")
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
import cv2
22
import time
3+
34
print("Press Space-bar to click Selfie")
45
print("Press Escape key to terminate the window")
56
time.sleep(5)
67
cam = cv2.VideoCapture(0)
78
cv2.namedWindow("Take selfie with python")
8-
img=0
9+
img = 0
910
while True:
1011
ret, frame = cam.read()
1112

1213
if not ret:
13-
print("Failed to grab frame")
14+
print("Failed to grab frame")
1415
break
1516

16-
cv2.imshow("Take selfie with python",frame)
17+
cv2.imshow("Take selfie with python", frame)
1718
k = cv2.waitKey(1)
18-
if k%256 == 27:
19+
if k % 256 == 27:
1920
print("Escape hit, closing the window")
2021
break
21-
if k%256 == 32:
22+
if k % 256 == 32:
2223
img_name = f"Selfie_{img}.jpg"
23-
cv2.imwrite(img_name,frame)
24+
cv2.imwrite(img_name, frame)
2425
print("Selfie taken!")
25-
img+=1
26+
img += 1
2627
cam.release
2728
cv2.destroyAllWindows()

projects/Voice-to-Text/main.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
import speech_recognition as sr
2-
from googletrans import Translator
2+
from googletrans import Translator
3+
34

45
# obtain audio from the microphone
56
def Listen(): # initializing funtion for voice to text
67
r = sr.Recognizer()
78
with sr.Microphone() as source:
89
print("Say something!")
910
# setting threshhold frequency for better output
10-
r.pause_threshhold=1
11-
audio = r.listen(source,0,8)
12-
11+
r.pause_threshhold = 1
12+
audio = r.listen(source, 0, 8)
13+
1314
# recognize speech using google
1415
try:
1516
print("Recognising")
16-
query=r.recognize_google(audio,language="en")
17+
query = r.recognize_google(audio, language="en")
1718
except sr.UnknownValueError:
1819
print("Could not understand audio")
1920
except sr.RequestError as e:
2021
print("Error Occured; {0}".format(e))
21-
except :
22+
except:
2223
return ""
23-
query=str(query).lower() # converting the query into string
24+
query = str(query).lower() # converting the query into string
2425
return query
2526

27+
2628
# printing the desired voice input into required text output
2729
print(Listen())
28-

0 commit comments

Comments
 (0)