Skip to content

Commit fa51f76

Browse files
committed
file formating according to PEP8 throught the repo
1 parent 2aaf73d commit fa51f76

20 files changed

+65
-64
lines changed

Algorithms/Search Algorithms/binary_search.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
def binary_sort(sorted_list, length, key):
55
start = 0
6-
end = length-1
6+
end = length - 1
77
while start <= end:
8-
mid = int((start + end)/2)
8+
mid = int((start + end) / 2)
99
if key == sorted_list[mid]:
1010
print("\nEntered number %d is present "
1111
"at position: %d" % (key, mid))
@@ -17,6 +17,7 @@ def binary_sort(sorted_list, length, key):
1717
print("\nElement not found!")
1818
return -1
1919

20+
2021
lst = []
2122

2223
size = int(input("Enter size of list: \t"))

area_of_triangle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
s = (a + b + c) / 2
88

9-
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
9+
area = (s * (s - a) * (s - b) * (s - c)) ** 0.5
1010
print('The area of the triangle is %0.2f' % area)

arithmeticOperations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
num1 = int(input('Enter First number: '))
44
num2 = int(input('Enter Second number '))
5+
56
add = num1 + num2
67
dif = num1 - num2
78
mul = num1 * num2
89
div = num1 / num2
910
floor_div = num1 // num2
1011
power = num1 ** num2
1112
modulus = num1 % num2
13+
1214
print('Sum of ', num1, 'and', num2, 'is :', add)
1315
print('Difference of ', num1, 'and', num2, 'is :', dif)
1416
print('Product of ', num1, 'and', num2, 'is :', mul)
1517
print('Division of ', num1, 'and', num2, 'is :', div)
1618
print('Floor Division of ', num1, 'and', num2, 'is :', floor_div)
1719
print('Exponent of ', num1, 'and', num2, 'is :', power)
1820
print('Modulus of ', num1, 'and', num2, 'is :', modulus)
19-

armstrong.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
if int(input_num) == arm_num:
1414
print(input_num, 'is an ARMSTRONG number')
1515
else:
16-
print(input_num, 'is NOT an armstrong number')
16+
print(input_num, 'is NOT an armstrong number')
1717

1818
except ValueError:
1919
print("That's not a valid number, Try Again !")

average.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
numbers = float(input('Enter number : '))
88
total_sum += numbers
99

10-
avg = total_sum/num
10+
avg = total_sum / num
1111
print('Average of ', num, ' numbers is :', avg)

biggest_smallest_3numbers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ def smallest(num1, num2, num3):
2424
smallest_num = num3
2525
print("The smallest of the 3 numbers is : ", smallest_num)
2626

27+
2728
largest(number1, number2, number3)
2829
smallest(number1, number2, number3)

dictionaryOperations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'Gender': 'Male',
88
'Location': 'India',
99
'Website': 'programminginpython.com'
10-
}
10+
}
1111

1212
# print dictionary
1313
print(my_info)

digits_in_number.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
while input_num > 0:
77
count += 1
88
input_num //= 10
9-
print("The number of digits in the given number are:", count)
9+
print("The number of digits in the given number are:", count)

even_odd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
if input_num % 2 == 0:
66
print(input_num, "is EVEN")
77
else:
8-
print(input_num, "is ODD")
8+
print(input_num, "is ODD")

even_odd_lists.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
numbers = []
44
n = int(input("Enter number of elements: \t"))
55

6-
for i in range(1, 1+n):
6+
for i in range(1, 1 + n):
77
allElements = int(input("Enter element: \t"))
88
numbers.append(allElements)
99

@@ -18,4 +18,3 @@
1818

1919
print("Even numbers list \t", even_lst)
2020
print("Odd numbers list \t", odd_lst)
21-

fibonacci.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
__author__ = 'Avinash'
22

3+
34
def fibonacci(n):
45
if n == 1:
56
return 1
67
elif n == 0:
7-
return 0
8+
return 0
89
else:
9-
return fibonacci(n-1) + fibonacci(n-2)
10+
return fibonacci(n - 1) + fibonacci(n - 2)
11+
1012

1113
number = int(input("Enter an integer: \t"))
1214
for i in range(number):

file_operations.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,3 @@
3131

3232
# Delete a file
3333
os.remove("test.txt")
34-
35-

number_reverse_slice.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
print('Reverse of the given number is : ', str(num)[::-1])
88
except ValueError:
99
print("That's not a valid number, Try Again !")
10-

python_database_operations/delete_from_db.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
cursor.execute(sql)
1515
# Commit your changes in the database
1616
db.commit()
17-
except:
18-
# Rollback in case there is any error
19-
db.rollback()
17+
except pymysql.error:
18+
# Rollback in case there is any error
19+
db.rollback()
2020

2121
# disconnect from server
2222
db.close()

python_database_operations/insert_to_db.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
__author__ = 'Avinash'
42

53
import pymysql

python_database_operations/read_from_db.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
__author__ = 'Avinash'
2+
23
import pymysql
34

45
# Open database connection
@@ -20,10 +21,10 @@
2021
age = row[3]
2122
sex = row[4]
2223
# Now print fetched result
23-
print("fname = %s, lname = %s, age = %d, sex = %s" % \
24-
(fname, lname, age, sex, ))
25-
except:
26-
print("Error: unable to fetch data")
24+
print("fname = %s, lname = %s, age = %d, sex = %s" %
25+
(fname, lname, age, sex, ))
26+
except pymysql.Error:
27+
print("Error: unable to fetch data")
2728

2829
# disconnect from server
2930
db.close()

python_database_operations/update_to_db.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
cursor.execute(sql)
1515
# Commit your changes in the database
1616
db.commit()
17-
except:
18-
# Rollback in case there is any error
19-
db.rollback()
17+
except pymysql.error:
18+
# Rollback in case there is any error
19+
db.rollback()
2020

2121
# disconnect from server
22-
db.close()
22+
db.close()

sets_operations.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,29 @@
1818

1919
# function which finds even and odd numbers
2020
def even_odd_sets(num):
21-
if num % 2 == 0:
22-
even_numbers.add(num)
23-
else:
24-
odd_numbers.add(num)
21+
if num % 2 == 0:
22+
even_numbers.add(num)
23+
else:
24+
odd_numbers.add(num)
2525

2626

2727
# function which finds prime and composite numbers
2828
def prime_composite_sets(num):
29-
if num > 1:
30-
for j in range(2, num):
31-
if (num % j) == 0:
32-
composite_numbers.add(num)
33-
break
34-
else:
35-
prime_numbers.add(num)
29+
if num > 1:
30+
for j in range(2, num):
31+
if (num % j) == 0:
32+
composite_numbers.add(num)
33+
break
34+
else:
35+
prime_numbers.add(num)
3636

3737

3838
for i in range(1, 11):
39-
numbers.add(i)
39+
numbers.add(i)
4040

41-
even_odd_sets(i)
41+
even_odd_sets(i)
4242

43-
prime_composite_sets(i)
43+
prime_composite_sets(i)
4444

4545

4646
print("\nNumbers Set: ", numbers)
@@ -65,7 +65,7 @@ def prime_composite_sets(num):
6565

6666
# Difference of sets
6767
print("Difference between numbers and prime_numbers:",
68-
numbers-prime_numbers)
68+
numbers - prime_numbers)
6969

7070

7171
example = set(['test', 43, 'another', 120])
@@ -81,4 +81,3 @@ def prime_composite_sets(num):
8181
# Clear the set
8282
example.clear()
8383
print(example)
84-

simple_calci.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
__author__ = 'Avinash'
2-
2+
33
import tkinter as tk
44
from functools import partial
5-
6-
5+
6+
77
def call_result(label_result, n1, n2):
88
num1 = (n1.get())
99
num2 = (n2.get())
10-
result = int(num1)+int(num2)
10+
result = int(num1) + int(num2)
1111
label_result.config(text="Result is %d" % result)
1212
return
13-
13+
14+
1415
root = tk.Tk()
1516
root.geometry('400x200+100+200')
1617
root.title('Simple Calculator')
17-
18+
1819
number1 = tk.StringVar()
1920
number2 = tk.StringVar()
20-
21+
2122
labelTitle = tk.Label(root, text="Simple Calculator").grid(row=0, column=2)
2223
labelNum1 = tk.Label(root, text="Enter a number").grid(row=1, column=0)
2324
labelNum2 = tk.Label(root, text="Enter another number").grid(row=2, column=0)
2425
labelResult = tk.Label(root)
2526
labelResult.grid(row=7, column=2)
26-
27+
2728
entryNum1 = tk.Entry(root, textvariable=number1).grid(row=1, column=2)
2829
entryNum2 = tk.Entry(root, textvariable=number2).grid(row=2, column=2)
2930
call_result = partial(call_result, labelResult, number1, number2)

temperature_converter_GUI.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33
import tkinter as tk
44
from functools import partial
55

6-
#global variable
6+
# global variable
77
tempVal = "Celsius"
88

99

10-
#getting drop down value
10+
# getting drop down value
1111
def store_temp(sel_temp):
1212
global tempVal
1313
tempVal = sel_temp
1414

1515

16-
#the main conversion
16+
# the main conversion
1717
def call_convert(rlabel1, rlabe12, inputn):
1818
tem = inputn.get()
1919
if tempVal == 'Celsius':
20-
f = float((float(tem) * 9/5) + 32)
20+
f = float((float(tem) * 9 / 5) + 32)
2121
k = float((float(tem) + 273.15))
2222
rlabel1.config(text="%f Fahrenheit" % f)
2323
rlabe12.config(text="%f Kelvin" % k)
2424
if tempVal == 'Fahrenheit':
25-
c = float((float(tem) - 32) * 5/9)
25+
c = float((float(tem) - 32) * 5 / 9)
2626
k = c + 273
2727
rlabel1.config(text="%f Celsius" % c)
2828
rlabe12.config(text="%f Kelvin" % k)
@@ -33,7 +33,8 @@ def call_convert(rlabel1, rlabe12, inputn):
3333
rlabe12.config(text="%f Fahrenheit" % f)
3434
return
3535

36-
#app window configuration and UI
36+
37+
# app window configuration and UI
3738
root = tk.Tk()
3839
root.geometry('400x150+100+200')
3940
root.title('Temperature Converter')
@@ -45,29 +46,29 @@ def call_convert(rlabel1, rlabe12, inputn):
4546
numberInput = tk.StringVar()
4647
var = tk.StringVar()
4748

48-
#label and entry field
49+
# label and entry field
4950
input_label = tk.Label(root, text="Enter temperature", background='#09A3BA', foreground="#FFFFFF")
5051
input_entry = tk.Entry(root, textvariable=numberInput)
5152
input_label.grid(row=1)
5253
input_entry.grid(row=1, column=1)
5354

54-
#result label's for showing the other two temperatures
55+
# result label's for showing the other two temperatures
5556
result_label1 = tk.Label(root, background='#09A3BA', foreground="#FFFFFF")
5657
result_label1.grid(row=3, columnspan=4)
5758
result_label2 = tk.Label(root, background='#09A3BA', foreground="#FFFFFF")
5859
result_label2.grid(row=4, columnspan=4)
5960

60-
#drop down initalization and setup
61+
# drop down initalization and setup
6162
dropDownList = ["Celsius", "Fahrenheit", "Kelvin"]
6263
dropdown = tk.OptionMenu(root, var, *dropDownList, command=store_temp)
6364
var.set(dropDownList[0])
6465
dropdown.grid(row=1, column=3)
6566
dropdown.config(background='#09A3BA', foreground="#FFFFFF")
6667
dropdown["menu"].config(background='#09A3BA', foreground="#FFFFFF")
6768

68-
#button click
69+
# button click
6970
call_convert = partial(call_convert, result_label1, result_label2, numberInput)
7071
result_button = tk.Button(root, text="Convert", command=call_convert, background='#09A3BA', foreground="#FFFFFF")
7172
result_button.grid(row=2, columnspan=4)
7273

73-
root.mainloop()
74+
root.mainloop()

0 commit comments

Comments
 (0)