forked from SushmitaY/mca101_2017
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcosine.py
More file actions
41 lines (32 loc) · 884 Bytes
/
cosine.py
File metadata and controls
41 lines (32 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def myCosine(n):
'''
objective: to calculate cosine of a number
approach: using series
input parameter: n -> the number whose cosine needs to be calculated
result: cosine of a number
'''
term = 1
total = 0;
multiplyBy = - n ** 2
divideBy = 1
nextIntSeq = 1
epsilon = 0.0001
while abs(term) > epsilon:
total += term
divideBy = nextIntSeq * (nextIntSeq + 1)
term *= multiplyBy / divideBy
nextIntSeq += 2
return total
def main():
'''
objective: to calculate cosine of a number
result: cosine of a number
'''
#approach: using function myCosine
n = float(input('Enter a number whose cosine: '))
result = myCosine(n)
print('\nCosine(', n ,') : ', result)
print('End of main')
if __name__ == '__main__':
main()
print('End of function')