-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday6.py
More file actions
77 lines (58 loc) · 1.75 KB
/
Copy pathday6.py
File metadata and controls
77 lines (58 loc) · 1.75 KB
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
#✅ 🏆 Day 6 – Problem Solving Pack
"""🔶 Problem 1: Find the Odd Integer
Problem:
Given an array of integers where all values appear an even number of times except one, return the integer that appears an odd number of times.
Example:
find_odd([20, 1, 1, 2, 2, 3, 3]) ➞ 20
find_odd([10, 10, 10, 10, 11]) ➞ 11
find_odd([5, 5, 5, 4, 4]) ➞ 5"""
def find_odd(lst):
checked = []
count = 0
for n in lst:
if n not in checked:
count = lst.count(n)
if count % 2 != 0:
return n
checked.append(n)
lst =[3, 4, 4, 5, 5, 20, 20, 7, 7, 7]
print(find_odd(lst))
print(find_odd([20, 1, 1, 2, 2, 3, 3]))
print(find_odd([10, 10, 10, 10, 11]))
print(find_odd([5, 5, 5, 3, 3]))
print("Print function :")
#print function
def find_odd(lst):
checked = []
count = 0
for n in lst:
if n not in checked:
count = lst.count(n)
if count % 2 != 0:
print(n)
checked.append(n)
lst =[3, 4, 4, 5, 5, 20, 20, 7, 7, 7]
find_odd(lst)
find_odd([20, 1, 1, 2, 2, 3, 3])
find_odd([10, 10, 10, 10, 11])
find_odd([5, 5, 5, 4, 4])
"""🔶 Problem 2: Age Difference
Problem:
You are given a list of integers representing ages. Return the difference between the oldest and youngest person (i.e., max(age) - min(age)).
Example:
age_diff([10, 15, 20, 25]) ➞ 15
age_diff([100, 50]) ➞ 50
age_diff([1, 1, 1]) ➞ 0"""
def age_diff(lst):
max = lst[0]
mini = lst[0]
for i in range(1, len(lst)):
if max < lst[i]:
max = lst[i]
elif mini > lst[i]:
mini = lst[i]
return max - mini
print(age_diff([10, 15, 20, 25]))
print(age_diff([100, 50]))
print(age_diff([1, 1, 1]))
print(age_diff([99, 78, 87, 4]))