File tree Expand file tree Collapse file tree 3 files changed +20
-17
lines changed
Expand file tree Collapse file tree 3 files changed +20
-17
lines changed Original file line number Diff line number Diff line change 1+ # Program that prints out the fibonacci sequence until a given number
2+
13def calc_fib (num ):
2- while len (fib )<= num :
4+ while len (fib ) <= num :
35 n = len (fib )
4- fib .append ((fib [n - 1 ]+ fib [n - 2 ]))
6+ fib .append ((fib [n - 1 ] + fib [n - 2 ]))
57
68def main ():
79 print ("Enter the Position of the Number in the Sequence or \' 0\' to Quit: " )
810 num = 0
911 fib = list ()
1012 fib .append (0 )
1113 fib .append (1 )
14+
1215 while True :
1316 num = int (input ())
14- if (num <= 0 ):
17+ if (num <= 0 ):
1518 break
1619
17- if len (fib )<= num :
20+ if len (fib ) <= num :
1821 calc_fib (num )
1922
20- print ('Fibonacci Number at Position ' + str (num )+ ' is: ' + str (fib [num ]))
23+ print ('Fibonacci Number at Position ' + str (num ) + ' is: ' + str (fib [num ]))
2124
2225if __name__ == '__main__' :
2326 main ()
Original file line number Diff line number Diff line change 77"""
88# Iterative Solution
99def gcd (x , y ):
10- if x == 0 :
10+ if x == 0 :
1111 return y
12- if y == 0 :
12+ if y == 0 :
1313 return x
1414
15- while x % y != 0 :
16- rem = x % y ;
15+ while x % y != 0 :
16+ rem = x % y ;
1717 x = y
1818 y = rem
1919
2020 return y
2121
2222# Recursive Solution
2323def gcd (x , y ):
24- if x == 0 :
24+ if x == 0 :
2525 return y
26- if y == 0 :
26+ if y == 0 :
2727 return x
2828
29- return gcd (y , x % y )
29+ return gcd (y , x % y )
Original file line number Diff line number Diff line change 11def prime (limit ):
22
33 count = 1
4- while (count < limit ):
4+ while (count < limit ):
55
66 flag = 0
7- for i in range (3 ,count ,2 ):
8- if (count % i == 0 ):
7+ for i in range (3 , count , 2 ):
8+ if (count % i == 0 ):
99 flag = 1
1010
11- if (flag == 0 ):
11+ if (flag == 0 ):
1212 print (count )
1313
14- count += 2
14+ count += 2
1515
1616prime (100 )
You can’t perform that action at this time.
0 commit comments