Results 1 to 7 of 7

Thread: stupid Python question (+reeepppp)

  1. #1
    Poem's Avatar
    Joined
    Feb 2013
    Posts
    986
    Userbars
    9
    Thanks
    821
    Thanked
    678/277
    DL/UL
    41/0
    Mentioned
    247 times
    Time Online
    86d 16h 7m
    Avg. Time Online
    30m

    stupid Python question (+reeepppp)

    i have a very simple question pertaining the code below.

    Code:
    for number in range(35225124124214152):
      if number <= 5:
        print "x"
      else:
        print "y"
    instead of going through 35225124124214152 numbers before printing out the results, how can I have the numbers printed one at a time?

    (printing out the result for number 1 before moving on to check number 2)

    thanks in advance.

  2. #2



    Ghosts's Avatar
    Joined
    Jul 2013
    Posts
    1,527
    Userbars
    9
    Thanks
    957
    Thanked
    981/359
    DL/UL
    81/3
    Mentioned
    451 times
    Time Online
    187d 15h 9m
    Avg. Time Online
    1h 8m
    Quote Originally Posted by Poem View Post
    i have a very simple question pertaining the code below.

    Code:
    for number in range(35225124124214152):
      if number <= 5:
        print "x"
      else:
        print "y"
    instead of going through 35225124124214152 numbers before printing out the results, how can I have the numbers printed one at a time?

    (printing out the result for number 1 before moving on to check number 2)

    thanks in advance.
    Do you mean you want it to go through them all and then print out the results? Right now it is printing them out as it goes. If you have it pause between numbers you can see that it prints out one at a time.

    Code:
    import time
    
    for number in range(1000):
      if number <= 5:
        print "x"
      else:
        print "y"
    
      time.sleep(5)

  3. #3
    |2eap's Avatar
    Joined
    Jun 2013
    Posts
    3,458
    Userbars
    17
    Thanks
    2,494
    Thanked
    2,680/1,389
    DL/UL
    75/0
    Mentioned
    822 times
    Time Online
    111d 11h 4m
    Avg. Time Online
    40m
    i taught him that

  4. #4
    Water's Avatar
    Joined
    Nov 2012
    Posts
    792
    Userbars
    12
    Thanks
    474
    Thanked
    452/210
    DL/UL
    158/9
    Mentioned
    217 times
    Time Online
    54d 9h 37m
    Avg. Time Online
    18m
    Quote Originally Posted by Poem View Post
    i have a very simple question pertaining the code below.

    Code:
    for number in range(35225124124214152):
      if number <= 5:
        print "x"
      else:
        print "y"
    instead of going through 35225124124214152 numbers before printing out the results, how can I have the numbers printed one at a time?

    (printing out the result for number 1 before moving on to check number 2)

    thanks in advance.
    Code:
    for number in range(35225124124214152):
      if number <= '5':
        print "x"
      else:
        print "y"
    Try '' around the five

  5. #5



    Ghosts's Avatar
    Joined
    Jul 2013
    Posts
    1,527
    Userbars
    9
    Thanks
    957
    Thanked
    981/359
    DL/UL
    81/3
    Mentioned
    451 times
    Time Online
    187d 15h 9m
    Avg. Time Online
    1h 8m
    Quote Originally Posted by Water View Post
    Code:
    for number in range(35225124124214152):
      if number <= '5':
        print "x"
      else:
        print "y"
    Try '' around the five
    range() generates an array of integers. Putting single/double quotes around the 5 turns the 5 from an int to a string so you would be comparing the int from the array that range generates, to a string, '5'. You wouldn't get the expected results with that.
    Last edited by Ghosts; 11-01-2014 at 07:52 PM.

  6. The Following User Says Thank You to Ghosts For This Useful Post:

    Water (11-02-2014)

  7. #6
    txtsd's Avatar
    Joined
    Dec 2012
    Posts
    642
    Userbars
    7
    Thanks
    538
    Thanked
    327/146
    DL/UL
    60/2
    Mentioned
    91 times
    Time Online
    31d 8h 56m
    Avg. Time Online
    10m
    Quote Originally Posted by Poem View Post
    i have a very simple question pertaining the code below.

    Code:
    for number in range(35225124124214152):
      if number <= 5:
        print "x"
      else:
        print "y"
    instead of going through 35225124124214152 numbers before printing out the results, how can I have the numbers printed one at a time?

    (printing out the result for number 1 before moving on to check number 2)

    thanks in advance.
    It's already doing that. Why such a big number anyway? It will take ages to complete to loop, and even more time since it's printing "y" 35225124124214146 times. On windows, you can run the program and come back after 2 days and it will still be printing "y"s because the terminal actually updates for each print.

  8. #7
    Poem's Avatar
    Joined
    Feb 2013
    Posts
    986
    Userbars
    9
    Thanks
    821
    Thanked
    678/277
    DL/UL
    41/0
    Mentioned
    247 times
    Time Online
    86d 16h 7m
    Avg. Time Online
    30m
    i got it, thanks guys!

    i've been using the wrong python interpreter!
    @(you need an account to see links) it was just an arbitrary number this isnt' the actual code but a simplified version to show what i was trying to do

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •