Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+9 votes

Hey guys, for question one I'm a little confused about how to print how many positive and negative numbers. I can get the sums and everything but don't know how to say 'There were 3 positive numbers' and so on.

asked in CSC201 Spring 2021 by (1 point)

3 Answers

+3 votes

So when you make your sum, you set your variable to add to itself every loop. This is done with something like

theSum = theSum + inputNumber

which it sounds like youve already done. so to keep track of how MANY numbers are being summed, you need another variable, which adds 1 to itself every loop. something like

y = y + 1

and then you just have to work out how to make it so that every time theSum is increased, your other variable increases by 1.

answered by (1 point)
0

Awesome, thanks Furby!

0

Good, but "y" is not a descriptive variable name, so use a name like positiveCount instead!

+3 votes

I made an if statement.

If number > 0:
   positiveCount = positiveCount + 1

And the same with negative

answered by (1 point)
0

Thanks Eirik!

+2 votes

Did you get this fixed? I tried the suggestions below and my positiveCount keeps equalling 1...

answered by (1 point)
...