forked from imtiazahmad007/PythonCourse
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassignment_08.py
81 lines (31 loc) · 800 Bytes
/
assignment_08.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
# Assignment 8
"""
Return the sum of the numbers in the list, except ignore sections of
numbers starting with a 7 and extending to the next 8
(every 7 will be followed by at least one 8).
Return 0 for no numbers.
EXAMPLE:
sum78([1, 2, 2]) → 5
sum78([1, 2, 2, 7, 99, 99, 8]) → 5
sum78([1, 1, 7, 8, 2]) → 4
"""
#Your Code Below:
print(sum78([1, 2, 2])) #→ 5
print(sum78([1, 2, 2, 7, 99, 99, 8])) #→ 5
print(sum78([1, 1, 7, 8, 2])) #→ 4
# Solution:
# def sum78(nums):
# sum = 0
# inRange = False
#
# for i in range(len(nums)):
# if nums[i] == 7:
# inRange = True
#
# if not inRange:
# sum += nums[i]
#
# if inRange and nums[i] == 8:
# inRange = False
#
# return sum