Tuesday, December 6, 2016

blog 32

Look at the program below.
How do we fix it so it will print the string one letter at a time in the loop?
What one thing can we change to get it to work?

s= "hey dudes!"

for i in range(8):
     print s[i]

15 comments:

  1. s= "hey dudes!"

    for i in range(9):
    print s[i]

    travis vonheeder

    ReplyDelete
  2. for i in range(8):
    s= "hey dudes!"
    print (s[i])

    - Owen Luther

    ReplyDelete
  3. move the statement down into the loop.

    jonathan

    ReplyDelete
  4. Chris VanYe

    s= "hey dudes!"

    for i in range(10):
    print s[i]

    ReplyDelete
  5. We can change the range to 9 so it prints through "!"
    -Katelyn

    ReplyDelete
  6. h
    e
    y

    d
    u
    d
    e
    s
    !
    Alex Haston

    ReplyDelete
  7. for i in range(10):
    print s[i]
    Josh Lee

    ReplyDelete
  8. h
    e
    y

    d
    u
    d
    e
    s
    !
    -Gary Gao

    ReplyDelete
  9. s = ("hey dudes")

    for i in range(9):
    print s[i]
    add parenthesis and account for the space

    -Sean

    ReplyDelete
  10. Actually, it needs parentheses around s[i] in order to run in IDLE
    and range needs to go to 10
    -Katleyn

    ReplyDelete
  11. You have to fix the loop by implementing the len function so it can get the length of the string type variable 's'
    like this:

    s = "hey dudes!"

    for i in range(len(s)):
    print s[i]

    You can also change the range to 10 since everything starts from 0 in programming.

    - Abby Peterson

    ReplyDelete
  12. change for I in range(8)to 1.
    -Lux lei

    ReplyDelete
  13. s= "hey dudes!"

    for s in range(8):
    print s[i]
    Charlie Lin

    ReplyDelete
  14. 1. there needs to be a parenthesis around s[i].
    2. We should also change the 8 to 10 so that ti prints the entire thing.
    -Joe Haj

    ReplyDelete