Python Forum
How to find the sum of even numbers from entered N numbers?
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to find the sum of even numbers from entered N numbers?
#1
my question here
n=int(input('Enter the number:'))
if(n<=0):
print('Enter a valid number')
else:
sum=0
count = 0
while(n>0):
for count in range (i % 2 ==0)
sum+=n
n-=1
print(sum)
my code here
Reply
#2
n=int(input('Enter the number:'))
if(n<=0):
    print('Enter a valid number')
else:
    sum=0
    x = 0
    while(n>0):
        for x in range(0,n+1):
            if(x%2==0):
                sum=sum+x
                n=n-2
    print(sum)
===================== RESTART: C:/python/program/test.py =====================
Enter the number:10
30
>>>
===================== RESTART: C:/python/program/test.py =====================
Enter the number:20
110
Reply
#3
end = int(input("Give me a number: "))
total = sum(range(0, end+1, 2))
print(total)
idk why you guys are trying to make it so complicated...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python code to calculate mean of an array of numbers using numpy viren 3 146 May-29-2024, 04:49 PM
Last Post: Gribouillis
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 8 15,939 Jan-05-2024, 08:30 PM
Last Post: sgrey
  random numbers, randint janeik 2 642 Nov-27-2023, 05:17 PM
Last Post: janeik
  Advancing Page Numbers knight2000 4 1,090 May-24-2023, 09:14 AM
Last Post: knight2000
  Pulling Specifics Words/Numbers from String bigpapa 2 848 May-01-2023, 07:22 PM
Last Post: bigpapa
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,661 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,520 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  prime numbers with iterator and generator cametan_001 8 2,002 Dec-17-2022, 02:41 PM
Last Post: cametan_001
  List of random numbers astral_travel 17 2,893 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  Remove numbers from a list menator01 4 1,474 Nov-13-2022, 01:27 AM
Last Post: menator01

Forum Jump:

User Panel Messages

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