-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumAnalysisEngine_2.py
More file actions
47 lines (33 loc) · 1.24 KB
/
Copy pathnumAnalysisEngine_2.py
File metadata and controls
47 lines (33 loc) · 1.24 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
nums = [12, -5, 0, 7, -3, 18, 21, 4]
def classify_num(nums):
pos = neg = zero = 0
for i in range(len(nums)):
if (nums[i]>0):
pos += 1
print(f"the number: {nums[i]} is positive having index {i}")
elif (nums[i]==0):
zero += 1
print(f"the number: {nums[i]} is zero having index {i}")
else:
neg += 1
print(f"the number: {nums[i]} is negative having index {i}")
return pos, neg, zero
def find_even_positive(nums):
for i in range(len(nums)):
if (nums[i]>0 and nums[i]%2==0):
return nums[i]
return None
def div_by_3_not_by_2(nums):
result = []
for i in range(len(nums)):
if (nums[i]%3 == 0 and nums[i]%2 != 0):
result.append(nums[i])
return result
print(f"---- Number analysis engine ----")
print(f"Printing analysis of each no.: ")
pos,neg,zero = classify_num(nums)
print(f"The total positive no. is : {pos} and total negative no. is : {neg} and total count of zeroes {zero}")
first_even = find_even_positive(nums)
print(f"The first even positive no. is : {first_even}")
special_num = div_by_3_not_by_2(nums)
print(f"Numbers divisible by 3 but not by 2: {special_num}")