Python Forum
Supposed to print out even numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Supposed to print out even numbers
#1
When I execute this code:

list1 = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
num = 0
# using while loop
while (num < len(list1)):

    # checking condition
    if num % 2 == 0:
        print(list1[num], end=" ")

        # increment num
    num += 1
The output I am getting is:

1 9 25 49 81

I can't see why. The code comes from Geeks for Geeks website.

Thanks
Reply


Messages In This Thread
Supposed to print out even numbers - by DallasPCMan - May-21-2020, 02:59 PM
RE: Supposed to print out even numbers - by Yoriz - May-21-2020, 03:23 PM
RE: Supposed to print out even numbers - by GOTO10 - May-21-2020, 03:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python class doesn't invoke setter during __init__, not sure if's not supposed to? mtldvl 2 3,245 Dec-30-2021, 04:01 PM
Last Post: mtldvl
  Print max numbers in a list jimmoriarty 1 2,120 Sep-25-2020, 07:29 AM
Last Post: DPaul
  Is there a way i print odd and even numbers separately? spalisetty06 5 2,658 Jul-21-2020, 06:48 PM
Last Post: spalisetty06
  first k non prime numbers print bsrohith 7 7,425 Jun-20-2019, 10:48 AM
Last Post: arycloud
  my function is stuck on loop - even when it not supposed to be korenron 2 2,324 May-26-2019, 12:31 PM
Last Post: korenron
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,667 May-09-2019, 12:19 PM
Last Post: Pleiades
  Why can't I print numbers in Python? skrivver99 2 2,732 Nov-04-2018, 09:47 PM
Last Post: snippsat
  How to test a function that is supposed to return NoneType? w0mb4rt 1 3,448 Feb-17-2018, 07:38 PM
Last Post: Gribouillis
  Print list from splitted range of numbers prashant8530 1 2,766 Sep-04-2017, 08:03 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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