@@ -34,13 +34,70 @@ def average():
3434 return sum (nums ) / len (nums )
3535
3636
37+ def factorial (num ):
38+
39+ answer = 1
40+ for i in range (num ):
41+ answer *= i + 1
42+ return answer
43+
44+ def complexarithmetic ():
45+ print ("Enter '1' for complex addition" )
46+ print ("Enter '2' for complex substraction" )
47+ print ("Enter '3' for complex multiplication" )
48+ print ("Enter '4' for complex division" )
49+ choice = (input ("enter your choice" ))
50+ if choice == "1" :
51+ nums = list (map (int , input ("Enter all numbers seperated by space: " ).split ()))
52+ real_sum = 0
53+ imag_sum = 0
54+ for i in range (0 ,len (nums )- 1 ,2 ):
55+ real_sum += nums [i ]
56+ for i in range (2 ,len (nums )- 1 ,2 ):
57+ imag_sum += nums [i ]
58+ imag_sum += nums [- 1 ]
59+ return f"{ real_sum } + i{ imag_sum } "
60+
61+ elif choice == "2" :
62+ nums = list (map (int , input ("Enter all numbers seperated by space: " ).split ()))
63+ real_sub = nums [0 ]
64+ imag_sub = nums [1 ]
65+ for i in range (2 ,len (nums )- 1 ,2 ):
66+ real_sub -= nums [i ]
67+ for i in range (3 ,len (nums )- 1 ,2 ):
68+ imag_sub -= nums [i ]
69+ imag_sub -= nums [- 1 ]
70+ return f"{ real_sub } + i{ imag_sub } "
71+
72+ elif choice == "3" :
73+ nums = list (map (int , input ("Enter all numbers seperated by space maximum 4 elements: " ).split ()))
74+ real = (nums [0 ]* nums [2 ]- nums [1 ]* nums [3 ])
75+ imag = (nums [0 ]* nums [3 ]+ nums [2 ]* nums [1 ])
76+ return f"{ real } + i{ imag } "
77+
78+ elif choice == "4" :
79+ nums = list (map (int , input ("Enter all numbers seperated by space maximum 4 elements: " ).split ()))
80+ real = ((nums [0 ]* nums [2 ]+ nums [1 ]* nums [3 ])/ (nums [2 ]** 2 + nums [3 ]** 2 ))
81+ imag = ((nums [1 ]* nums [2 ] - nums [0 ]* nums [3 ])/ (nums [2 ]** 2 + nums [3 ]** 2 ))
82+ return f"{ real } + i{ imag } "
83+
84+ def binomail (num ):
85+ result = factorial (num [0 ])/ (factorial (num [1 ])* factorial (num [0 ]- num [1 ]))
86+ return result
87+
88+
89+
90+
3791c = 0
3892while c != "-1" :
3993 print ("Enter '1' for addition" )
4094 print ("Enter '2' for subtraction" )
4195 print ("Enter '3' for multiplication" )
4296 print ("Enter '4' for division" )
4397 print ("Enter '5' for average" )
98+ print ("Enter '6' for factorial" )
99+ print ("Enter '7' for complex arithmetic" )
100+ print ("ENter '8' for binomial" )
44101 print ("Enter '-1' to exit.\n " )
45102
46103 c = input ("Your choice is: " )
@@ -80,12 +137,43 @@ def average():
80137 time .sleep (2 )
81138 os .system ("cls" )
82139
140+ elif c == "6" :
141+ num = int (input ("enter the number: " ))
142+ if num < 0 :
143+ print ("Invalid entry" )
144+ continue
145+ res = factorial (num )
146+ os .system ("cls" )
147+ print (f"The answer is { res } " )
148+ time .sleep (2 )
149+ os .system ("cls" )
150+
151+ elif c == "7" :
152+ os .system ("cls" )
153+ print (complexarithmetic ())
154+ time .sleep (2 )
155+ os .system ("cls" )
156+
157+ elif c == "8" :
158+ os .system ("cls" )
159+ num = list (map (int ,input ("Enter the number seperated by space" ).split ()))
160+ if num [0 ]< num [1 ]:
161+ print ("Invalid entry" )
162+ continue
163+ res = binomail (num )
164+ os .system ("cls" )
165+ print (f"The answer is { res } " )
166+ time .sleep (2 )
167+ os .system ("cls" )
168+
169+
83170 elif c == "-1" :
84171 os .system ("cls" )
85172 print ("Thank you for using the calculator!" )
86173 time .sleep (2 )
87174 break
88175
176+
89177 else :
90178 os .system ("cls" )
91179 print ("Sorry, invalid option!" )
0 commit comments