#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    8
    Rep Power
    0

    Post Printing words in one line using for loop


    this is the code i think i ****ed things up cuz it only output Z

    b=""
    for c in range(0, 26):
    a=chr(ord('A')+c)
    a=b+a
    print(a)
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    157
    Rep Power
    2
    Originally Posted by renegade7
    this is the code i think i ****ed things up cuz it only output Z

    b=""
    for c in range(0, 26):
    a=chr(ord('A')+c)
    a=b+a
    print(a)
    It's hard to tell what indentation you had in mind for the print since you didn't use code tags. I think you're only real problem is that you kept updating "a" instead of "b". If that's so, here's what I did in v2.7 (should mostly work in v3._ except for the "print"):
    Code:
    >>> b=""
    >>> for c in range(0, 26):
    ...     a=chr(ord('A')+c)
    ...     b+=a
    ...
    >>> print b
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    >>>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    8
    Rep Power
    0
    Thanks alot you helped me out!
    But i have a question, Why would i update be when b is "" i tested in Python v3 and it worked. But i just couldn't comprehend it.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    157
    Rep Power
    2
    You are making "a" b a different character, a=chr(ord('A')+c), in each successive iteration. You want to append that character to an ever-growing string, "b", that was initialized to "".
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    ..


    ..
    Last edited by evol; December 25th, 2012 at 02:36 AM. Reason: ..

IMN logo majestic logo threadwatch logo seochat tools logo