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
  Complex Numbers Curbie 4 868 Feb-18-2025, 09:49 PM
Last Post: bowlofred
  [split] Prime numbers saima 1 522 Dec-09-2024, 02:19 AM
Last Post: jefsummers
  need help writing a program to run VIN numbers, any advice? Jhins007 4 1,135 Aug-23-2024, 08:06 AM
Last Post: DeaD_EyE
  python code to calculate mean of an array of numbers using numpy viren 3 1,115 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 20,745 Jan-05-2024, 08:30 PM
Last Post: sgrey
  random numbers, randint janeik 2 1,533 Nov-27-2023, 05:17 PM
Last Post: janeik
  Advancing Page Numbers knight2000 4 1,828 May-24-2023, 09:14 AM
Last Post: knight2000
  Pulling Specifics Words/Numbers from String bigpapa 2 1,563 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 3,026 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  find random numbers that are = to the first 2 number of a list. Frankduc 23 6,949 Apr-05-2023, 07:36 PM
Last Post: Frankduc

Forum Jump:

User Panel Messages

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