-
Notifications
You must be signed in to change notification settings - Fork 47
/
exercise-1-10.py
67 lines (51 loc) · 1.35 KB
/
exercise-1-10.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
"""
Find the sum of all numbers that are divisible by 5 or 7 less than 100.
Present the solution in the form of calculate(). In response, call
calculate() function and print the result to the console.
Expected result:
1580
"""
from pickle import FALSE
def calculate():
sum_ = 0
for n in range(100):
if n%5 == 0 or n%7 == 0:
sum_ += n
return(sum_)
print(calculate())
# Fibonaci
"""
Consider the Fibonaci sequence. It is a sequence of natuarl numbers
defined recursively as follows:
- the first element of the sequence is 0
- the second element of the sequence is 1
- each next element of the sequence is the sum of the previous two elements.
The begining of the Fibonaci sequence:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...
Find the sum of all the even elements of the Fibonaci sequence with vlaues
less than 1,000,000(1million)
Expected result:
1089154
"""
def fibonaci_even():
a = 0
b = 1
total = 0
while a < 1000000:
if a%2 == 0:
total += a
a, b = b, a + b
return total
print(fibonaci_even())
"""
Check if a number is a prime number
"""
def isprime(num):
isprime = True
if num > 1:
for i in range(2, num):
if num % i == 0:
isprime = False
break
return isprime
print(f'isprime {isprime(2)}')