Create a python program that will accept positive or negative number and store it to a list. Accepting input will stop when empty input is encountered. Count and display all positive and negative number input and its index number in the list. Count and display all even and odd positive numbers and its index number. Exclude 0 input.
Example Output:
number 1: 78
number 2: 91
number 3: -5
number 4: 0
number 4: 8
number 5: -100
number 6: -2
number 7: 100
number 8:
There are 4 positive numbers
All positive numbers: 78 91 8 100
Positive numbers can be found at index number: 0 1 3 6
There are 3 negative numbers
All negative numbers: -5 -100 -2
Negative numbers can be found at index number: 2 4 5
There are 3 positive even numbers
Positive even numbers are: 78 8 100
Positive even numbers can be found at index: 0 3 6
There are 1 positive odd numbers
Positive odd numbers are: 91
Positive odd numbers can be found at index: 1
# Python program to count positive and negative numbers in a List
# list of numbers
list1 = [-10, -21, -4, -45, -66, 93, 11]
pos_count, neg_count = 0, 0
num = 0
# using while loop
while(num < len(list1)):
# checking condition
if list1[num] >= 0:
pos_count += 1
else:
neg_count += 1
# increment num
num += 1
print("Positive numbers in the list: ", pos_count)
print("Negative numbers in the list: ", neg_count)
Comments
Leave a comment