Skip to content

Commit a94299f

Browse files
authored
List 2
1 parent 2454a64 commit a94299f

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

List2.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
4+
# # Return the number of even ints in the given array. Note: the % "mod" operator computes the remainder, e.g. 5 % 2 is 1
5+
6+
# # def count_evens(nums):
7+
# count = 0
8+
# for n in nums:
9+
# count -= n%2-1
10+
# return count
11+
# count_evens([2, 1, 2, 3, 4])
12+
#
13+
14+
# # Return the sum of the numbers in the array, except ignore sections of numbers starting with a 6 and extending to the next 7 (every 6 will be followed by at least one 7). Return 0 for no numbers.
15+
16+
# In[2]:
17+
18+
19+
def sum67(nums):
20+
count =0
21+
blocked= False
22+
for n in nums:
23+
if n == 6:
24+
blocked = True
25+
continue
26+
if n == 7 and blocked:
27+
blocked = False
28+
continue
29+
if not blocked:
30+
count += n
31+
32+
return count
33+
sum67([1, 2, 2, 6, 99, 99, 7])
34+
35+
36+
# # Given an array length 1 or more of ints, return the difference between the largest and smallest values in the array. Note: the built-in min(v1, v2) and max(v1, v2) functions return the smaller or larger of two values.
37+
38+
# In[4]:
39+
40+
41+
def big_diff(nums):
42+
return max(nums)-min(nums)
43+
44+
big_diff([7, 2, 10, 9])
45+
46+
47+
# # Given an array of ints, return True if the array contains a 2 next to a 2 somewhere.
48+
#
49+
#
50+
51+
# In[5]:
52+
53+
54+
def has22(nums):
55+
for i,v in enumerate(nums[:-1]):
56+
if v == 2 and nums[i+1] == 2:
57+
return True
58+
return False
59+
60+
has22([1, 2, 1, 2])
61+
62+
63+
# In[ ]:
64+
65+
66+
67+

0 commit comments

Comments
 (0)