Just started learning python, so I'm very thankful for anyone who can help.
Anyways the task is to define a function that takes a list of numbers and returns 3 values - how many positive numbers, negative numbers and zeroes there are in the list.
The main program I need to use a loop that gets the user to input however many numbers he wants (must be between 3 and 6, and this has to be checked). these numbers that the user inputs are to be added to a list. Then I have to call a function that uses the list as the argument and then print the results that the function returns.
using a loop is obligatory.
def three(z):
np = 0
nn = 0
zeroes = 0
for y in z:
if x<0:
nn+=1
if x>0:
np+=1
if x==0:
zeroes+=1
print('there are ', np, ' positive numbers\nthere are ', nn, ' negative numbers\nthere are ', zeroes, ' zeros')
return (np, nn, zeroes)
num_list = []
a = 0
n = eval(input('input a number (bigger than 3, smaller than 6): '))
while n>3 and n<6:
if a < n:
x = eval(input('input a number: '))
num_list.append(x)
a+= 1
else:
break
three(num_list)
I made a loop and a function, but I'm pretty sure I messed up at the loop or somewhere else because it looks like I'm using a lot of variables and it looks more complicated then it should probably be.