-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnique-series.py
165 lines (116 loc) · 5 KB
/
Unique-series.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#Choosing options within Question 4
while True:
print("You can choose to view the following programs:")
print("A : This will show you the tribonacci series upto the number of terms you input!")
print("B : This will show you an unique cos series for the number of terms you input!")
print("C : This will show you the result of an unique series!")
print("Exit: You may exit the program!")
print()
choice = input("Enter the pattern you want to view - a/b/c/Exit: ")
#Program 4.a) - The Tribonacci series
if choice.lower() == "a":
print()
n = int(input("Enter the number of terms of the series you want to view: "))
f1 = 1
f2 = 1
f3 = 1
print("The Tribonacci series upto",n,"terms:")
print(f1,f2,f3,sep = " ",end = " ")
for i in range (4,n+1):
f4 = f1 + f2 + f3
f1 = f2
f2 = f3
f3 = f4
print(f4, end = " ")
print()
print()
#Program 4.b) - The result of the cos series
elif choice.lower() == "b":
import math
print()
n = int(input("Enter the number of terms of the series you want to view: "))
x1 = float(input("Enter a value for x in cos(x) in degree measure: "))
x = (x1 * 3.14) / 180
print("The angle measures",x,"radians!")
sum1 = 1
index = -1
for a in range(2,n+1,2):
factorial = 1
for j in range (1,a+1):
factorial *= j
term = ((x**a)*index)/factorial
sum1 += term
index *= -1
print("The sum of the series upto",n,"terms is",sum1)
print()
#Program 4.c) - The result of a unique series
elif choice.lower() == "c":
print()
n = int(input("Enter the number of terms of the series you want to view: "))
a = int(input("Enter an integer number of your choice: "))
sum2 = 0
index = 1
power = 1
for i in range(1,n+1):
m = (4*(i - 1)) + 1
factorial = 1
for j in range(1,m+1):
factorial *= m
sum2 += ((a**power)/factorial)*index
power += 2
index *= -1
print("The sum of the series upto",n,"terms is",sum2)
print()
elif choice.lower() == "exit":
print()
print("The program will end now!")
print("Thank you!")
break
else:
print("Invalid choice!Please choose again!\n")
continue
"""OUTPUT:
You can choose to view the following programs:
A : This will show you the tribonacci series upto the number of terms you input!
B : This will show you an unique cos series for the number of terms you input!
C : This will show you the result of an unique series!
Exit: You may exit the program!
Enter the pattern you want to view - a/b/c/Exit: a
Enter the number of terms of the series you want to view: 10
The Tribonacci series upto 10 terms:
1 1 1 3 5 9 17 31 57 105
You can choose to view the following programs:
A : This will show you the tribonacci series upto the number of terms you input!
B : This will show you an unique cos series for the number of terms you input!
C : This will show you the result of an unique series!
Exit: You may exit the program!
Enter the pattern you want to view - a/b/c/Exit: b
Enter the number of terms of the series you want to view: 10
Enter a value for x in cos(x) in degree measure: 180
The angle measures 3.14 radians!
The sum of the series upto 10 terms is -65541.41041614303
You can choose to view the following programs:
A : This will show you the tribonacci series upto the number of terms you input!
B : This will show you an unique cos series for the number of terms you input!
C : This will show you the result of an unique series!
Exit: You may exit the program!
Enter the pattern you want to view - a/b/c/Exit: c
Enter the number of terms of the series you want to view: 10
Enter an integer number of your choice: 5
The sum of the series upto 10 terms is 4.960008065913282
You can choose to view the following programs:
A : This will show you the tribonacci series upto the number of terms you input!
B : This will show you an unique cos series for the number of terms you input!
C : This will show you the result of an unique series!
Exit: You may exit the program!
Enter the pattern you want to view - a/b/c/Exit: d
Invalid choice!Please choose again!
You can choose to view the following programs:
A : This will show you the tribonacci series upto the number of terms you input!
B : This will show you an unique cos series for the number of terms you input!
C : This will show you the result of an unique series!
Exit: You may exit the program!
Enter the pattern you want to view - a/b/c/Exit: exit
The program will end now!
Thank you!
"""