@@ -25,10 +25,10 @@ def multiplication():
2525def division ():
2626 n1 = float (input ("Enter first number: " ))
2727 n2 = float (input ("Enter second number: " ))
28- if n2 == 0 :
28+ if n2 == 0 :
2929 print ("Invalid entry" )
3030 return "Invalid entry"
31- print (n1 / n2 )
31+ print (n1 / n2 )
3232
3333 return n1 / n2
3434
@@ -39,59 +39,72 @@ def average():
3939
4040
4141def factorial (num ):
42-
43- answer = 1
42+ answer = 1
4443 for i in range (num ):
45- answer *= i + 1
44+ answer *= i + 1
4645 return answer
4746
47+
4848def complexarithmetic ():
4949 print ("Enter '1' for complex addition" )
5050 print ("Enter '2' for complex substraction" )
5151 print ("Enter '3' for complex multiplication" )
5252 print ("Enter '4' for complex division" )
53- choice = ( input ("enter your choice" ) )
54- if choice == "1" :
53+ choice = input ("enter your choice" )
54+ if choice == "1" :
5555 nums = list (map (int , input ("Enter all numbers seperated by space: " ).split ()))
56- real_sum = 0
57- imag_sum = 0
58- for i in range (0 ,len (nums )- 1 , 2 ):
59- real_sum += nums [i ]
60- for i in range (2 ,len (nums )- 1 , 2 ):
61- imag_sum += nums [i ]
62- imag_sum += nums [- 1 ]
56+ real_sum = 0
57+ imag_sum = 0
58+ for i in range (0 , len (nums ) - 1 , 2 ):
59+ real_sum += nums [i ]
60+ for i in range (2 , len (nums ) - 1 , 2 ):
61+ imag_sum += nums [i ]
62+ imag_sum += nums [- 1 ]
6363 return f"{ real_sum } + i{ imag_sum } "
6464
65- elif choice == "2" :
65+ elif choice == "2" :
6666 nums = list (map (int , input ("Enter all numbers seperated by space: " ).split ()))
67- real_sub = nums [0 ]
68- imag_sub = nums [1 ]
69- for i in range (2 ,len (nums )- 1 , 2 ):
70- real_sub -= nums [i ]
71- for i in range (3 ,len (nums )- 1 , 2 ):
72- imag_sub -= nums [i ]
73- imag_sub -= nums [- 1 ]
67+ real_sub = nums [0 ]
68+ imag_sub = nums [1 ]
69+ for i in range (2 , len (nums ) - 1 , 2 ):
70+ real_sub -= nums [i ]
71+ for i in range (3 , len (nums ) - 1 , 2 ):
72+ imag_sub -= nums [i ]
73+ imag_sub -= nums [- 1 ]
7474 return f"{ real_sub } + i{ imag_sub } "
7575
76- elif choice == "3" :
77- nums = list (map (int , input ("Enter all numbers seperated by space maximum 4 elements: " ).split ()))
78- real = (nums [0 ]* nums [2 ]- nums [1 ]* nums [3 ])
79- imag = (nums [0 ]* nums [3 ]+ nums [2 ]* nums [1 ])
76+ elif choice == "3" :
77+ nums = list (
78+ map (
79+ int ,
80+ input (
81+ "Enter all numbers seperated by space maximum 4 elements: "
82+ ).split (),
83+ )
84+ )
85+ real = nums [0 ] * nums [2 ] - nums [1 ] * nums [3 ]
86+ imag = nums [0 ] * nums [3 ] + nums [2 ] * nums [1 ]
8087 return f"{ real } + i{ imag } "
8188
82- elif choice == "4" :
83- nums = list (map (int , input ("Enter all numbers seperated by space maximum 4 elements: " ).split ()))
84- real = ((nums [0 ]* nums [2 ]+ nums [1 ]* nums [3 ])/ (nums [2 ]** 2 + nums [3 ]** 2 ))
85- imag = ((nums [1 ]* nums [2 ] - nums [0 ]* nums [3 ])/ (nums [2 ]** 2 + nums [3 ]** 2 ))
89+ elif choice == "4" :
90+ nums = list (
91+ map (
92+ int ,
93+ input (
94+ "Enter all numbers seperated by space maximum 4 elements: "
95+ ).split (),
96+ )
97+ )
98+ real = (nums [0 ] * nums [2 ] + nums [1 ] * nums [3 ]) / (nums [2 ] ** 2 + nums [3 ] ** 2 )
99+ imag = (nums [1 ] * nums [2 ] - nums [0 ] * nums [3 ]) / (nums [2 ] ** 2 + nums [3 ] ** 2 )
86100 return f"{ real } + i{ imag } "
87101
102+
88103def binomail (num ):
89- result = factorial (num [0 ])/ (factorial (num [1 ])* factorial (num [0 ]- num [1 ]))
104+ result = factorial (num [0 ]) / (factorial (num [1 ]) * factorial (num [0 ] - num [1 ]))
90105 return result
91106
92107
93-
94-
95108c = 0
96109while c != "-1" :
97110 print ("Enter '1' for addition" )
@@ -130,7 +143,7 @@ def binomail(num):
130143 elif c == "4" :
131144 res = division ()
132145 os .system ("cls" )
133- if res == "Invalid entry" :
146+ if res == "Invalid entry" :
134147 continue
135148 print (f"The answer is { res } " )
136149 time .sleep (2 )
@@ -145,7 +158,7 @@ def binomail(num):
145158
146159 elif c == "6" :
147160 num = int (input ("enter the number: " ))
148- if num < 0 :
161+ if num < 0 :
149162 print ("Invalid entry" )
150163 continue
151164 res = factorial (num )
@@ -154,16 +167,16 @@ def binomail(num):
154167 time .sleep (2 )
155168 os .system ("cls" )
156169
157- elif c == "7" :
170+ elif c == "7" :
158171 os .system ("cls" )
159172 print (complexarithmetic ())
160173 time .sleep (2 )
161174 os .system ("cls" )
162175
163- elif c == "8" :
176+ elif c == "8" :
164177 os .system ("cls" )
165- num = list (map (int ,input ("Enter the number seperated by space" ).split ()))
166- if num [0 ]< num [1 ]:
178+ num = list (map (int , input ("Enter the number seperated by space" ).split ()))
179+ if num [0 ] < num [1 ]:
167180 print ("Invalid entry" )
168181 continue
169182 res = binomail (num )
@@ -172,14 +185,12 @@ def binomail(num):
172185 time .sleep (2 )
173186 os .system ("cls" )
174187
175-
176188 elif c == "-1" :
177189 os .system ("cls" )
178190 print ("Thank you for using the calculator!" )
179191 time .sleep (2 )
180192 break
181193
182-
183194 else :
184195 os .system ("cls" )
185196 print ("Sorry, invalid option!" )
0 commit comments