Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
while after while
#1
I am new to Python and I am trying to make a program that lets the user input positive numbers. The program should then return a list of the numbers aswell as the number of even numbers in the list. I have written this piece of code.

numbers = []   # An empty list
print('Input positive whole numbers. Stop with zero.')
x = int(input('First number: '))
n = 0
i = 0
while x > 0:
    numbers.append(x)
    x = int(input('Next: '))
print('List:', numbers)    
while i < len(numbers):
    if numbers[i]%2 == 0:
        n += 1
        i += 1
print('Number of even numbers: ', n)
But it only returns the list and not the number of even numbers. Why?
Reply


Messages In This Thread
while after while - by WildP - Jan-28-2020, 01:19 PM
RE: while after while - by ThiefOfTime - Jan-28-2020, 01:29 PM
RE: while after while - by WildP - Jan-28-2020, 01:50 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020