While working at home, I thought I would try out python. I'm running 2.7.
I usually write in bash and one of the BASIC programs The Woz demo'd on the Apple 1 was: (converted to BASH)
This would provide:
0
01
012
0123
01234
012345
0123456
01234567
012345678
0123456789
012345678910
While trying to write this same code in Python, I do not get the desired result and I was wondering if anyone had any advice.
This provides:
0
01
012
0123
01234
012345
0123456
01234567
012345678
My questions are: 1. Why is the first line blank? 2. Why does the loop only go through 8? I notice there are 10 lines of output, but it's not what I'm looking for.
PS.. this is not homework.
I usually write in bash and one of the BASIC programs The Woz demo'd on the Apple 1 was: (converted to BASH)
Bash:
for i in {0..10}; do for ((j=0; j<=$i; j++)) do echo -n $j; done; echo ''; done;
0
01
012
0123
01234
012345
0123456
01234567
012345678
0123456789
012345678910
While trying to write this same code in Python, I do not get the desired result and I was wondering if anyone had any advice.
Python:
#!/usr/bin/python
import sys
# Define a main() function
def main():
for i in range(0,10):
for j in range(0,i):
print j,
sys.stdout.write('')
print
# This is the standard boilerplate that calls the main() function.
if __name__ == '__main__':
main()
0
01
012
0123
01234
012345
0123456
01234567
012345678
My questions are: 1. Why is the first line blank? 2. Why does the loop only go through 8? I notice there are 10 lines of output, but it's not what I'm looking for.
PS.. this is not homework.