PDA

View Full Version : stupid Python question (+reeepppp)



Poem
11-01-2014, 06:56 PM
i have a very simple question pertaining the code below.



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. :$

Ghosts
11-01-2014, 07:02 PM
i have a very simple question pertaining the code below.



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.


import time

for number in range(1000):
if number <= 5:
print "x"
else:
print "y"

time.sleep(5)

|2eap
11-01-2014, 07:08 PM
i taught him that

Water
11-01-2014, 07:26 PM
i have a very simple question pertaining the code below.



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. :$


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

Ghosts
11-01-2014, 07:46 PM
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.

txtsd
11-01-2014, 08:37 PM
i have a very simple question pertaining the code below.



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.

Poem
11-01-2014, 09:24 PM
i got it, thanks guys!

i've been using the wrong python interpreter!
txtsd it was just an arbitrary number :P this isnt' the actual code but a simplified version to show what i was trying to do