-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathswift_fibonacci.py
More file actions
40 lines (35 loc) · 799 Bytes
/
Copy pathswift_fibonacci.py
File metadata and controls
40 lines (35 loc) · 799 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
def is_prime(n):
for i in range(3, n):
if n % i == 0:
return n
return "BuzzFizz"
def fizzbuzz(n):
if n == 1:
return n
if n % 5 == 0 and n % 3 == 0:
return "FizzBuzz"
elif n % 5 == 0:
return "Fizz"
elif n % 3 == 0:
return "Buzz"
else:
# Check Prime
return is_prime(n)
# Main
num = input("Enter the number of elements in fibonacci series: ")
if num == 0:
print "No Fibonacci Series was generated for input",num
first = 0
second = 1
# Generate Fibonacci Series
for i in range(num):
if i == 0 or i == 1:
next = i
print next
continue
else:
next = first + second
first = second
second = next
# Check Fizz Buzz
print fizzbuzz(next)