Skip to content

Commit ba80e2c

Browse files
style: format code with autopep8
Format code with autopep8 This commit fixes the style issues introduced in 18e7cba according to the output from Autopep8. Details: https://app.deepsource.com/gh/avinashkranjan/Amazing-Python-Scripts/transform/50d4417f-05a6-4086-8fca-ce6153dce2fe/
1 parent 18e7cba commit ba80e2c

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

Number Conversion/converter_script.py

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,68 @@
11
import sys
2+
3+
24
class Definations:
35
'''Contains the actual logic for base conversion.
46
57
Parent class to Converter class
68
'''
7-
def __init__(self,number):
9+
10+
def __init__(self, number):
811
self.number = number
12+
913
def Decimal_to_Binary(self):
1014
return bin(int(self.number))[2:]
15+
1116
def Binary_to_Decimal(self):
12-
return int(str(self.number),2)
17+
return int(str(self.number), 2)
18+
1319
def Decimal_to_Octal(self):
1420
return oct(int(self.number))[2:]
21+
1522
def Octal_to_Decimal(self):
16-
return int(str(self.number),8)
23+
return int(str(self.number), 8)
24+
1725
def Decimal_to_Hexadecimal(self):
1826
return hex(self.number)[2:]
27+
1928
def Hexadecimal_to_Decimal(self):
20-
return int(str(self.number),16)
29+
return int(str(self.number), 16)
30+
2131
def Hexadecimal_to_Binary(self):
22-
num = int(str(self.number),16)
32+
num = int(str(self.number), 16)
2333
return bin(num)[2:]
34+
2435
def Hexadecimal_to_Octal(self):
25-
num = int(str(self.number),16)
36+
num = int(str(self.number), 16)
2637
return oct(num)[2:]
38+
2739
def Binary_to_Octal(self):
28-
num = int(str(self.number),2)
40+
num = int(str(self.number), 2)
2941
return oct(num)[2:]
42+
3043
def Binary_to_Hexadecimal(self):
31-
num = int(str(self.number),2)
44+
num = int(str(self.number), 2)
3245
return hex(num)[2:]
46+
3347
def Octal_to_Hexadecimal(self):
34-
num = int(str(self.number),8)
48+
num = int(str(self.number), 8)
3549
return hex(num)[2:]
50+
3651
def Octal_to_Binary(self):
37-
num = int(str(self.number),8)
52+
num = int(str(self.number), 8)
3853
return bin(num)[2:]
3954

55+
4056
class Converter(Definations):
4157
'''Inherits the Definations Class and converts the number based on user input'''
42-
def __init__(self,number):
58+
59+
def __init__(self, number):
4360
super().__init__(number)
4461

4562
def helper(self, func_name):
46-
return getattr(Definations,func_name)(self)
63+
return getattr(Definations, func_name)(self)
4764

48-
def convert(self,FROM="d",TO="b"):
65+
def convert(self, FROM="d", TO="b"):
4966
'''
5067
By Default conversion takes place from decimal to binary.
5168
specify the FROM and TO parameters from the following:
@@ -54,22 +71,27 @@ def convert(self,FROM="d",TO="b"):
5471
x-hexadecimal,
5572
o-octal
5673
'''
57-
bases = {'d':"Decimal",'b':"Binary",'x':'Hexadecimal','o':"Octal"}
74+
bases = {'d': "Decimal", 'b': "Binary",
75+
'x': 'Hexadecimal', 'o': "Octal"}
5876
to_call_function = bases[FROM] + '_to_' + bases[TO]
5977
return f"\n{self.number} in {bases[FROM]} = {self.helper(to_call_function)} in {bases[TO]}"
6078

79+
6180
def header_decoration():
6281
print('''
6382
-------------- WELCOME TO NUMBER CONVERTER --------------
6483
-------------- --------------------------- --------------
6584
''')
85+
86+
6687
def footer_decoration():
6788
print('''
6889
-------------- --------------------------- -----------
6990
''')
70-
71-
if __name__=='__main__':
91+
92+
93+
if __name__ == '__main__':
7294
header_decoration()
7395
Num = Converter(input("Enter number = "))
74-
print(Num.convert(input("From = "),input("To = ")))
96+
print(Num.convert(input("From = "), input("To = ")))
7597
footer_decoration()

0 commit comments

Comments
 (0)