Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Playing with time function. Not sure what I am doing wrong.

import time

quote = "Somtimes you just have to wait . . . and then the magic can happen"
words = quote.split

for word in words:
    print(word)
    time.sleep(1)

[MOD: added ```python formatting -cf]

2 Answers

Hey Matthew!

Actually, I was able to test your code and this works how you want it to (I assume):

import time

quote = "Sometimes you just have to wait . . . and then the magic can happen"

words = quote.split(" ") # you were missing the delimeter part of code here (" ") essentially split on the space

for word in words:
    print(word)
    time.sleep(1) # pause for 1 second

Make sure your indentation is exactly multiples of 4 spaces (4/8/16/20/etc...) (Don't use tabs)

BTW, I tested it here:

https://www.katacoda.com/courses/python/playground (FYI - I ran the code using):

>>> python3 app.py

I hope that helps.

Stay safe and happy coding!

Chris Freeman
Chris Freeman
Treehouse Moderator 68,454 Points

You can also use a default no parameter, as in split(), to split on whitespace. This has the advantage where multiple spaces don't result in "blank" words between the spaces.

When you use an assignment such as: words = quote.split without including the parens (), you are referencing the method object split, and not actually calling it to be executed. Python allows methods and functions to be reference and passed around as arguments. Another common mistake is to accidentally compare a string reference to a method by also forgetting the parens: response.lower == "no". This will never match because the left-side is a method reference. The correct way, of course, is response.lower() == "no"

Once again you've saved the day! Thanks Peter

Hey Matthew!

Could you send me your actual code?

I'm not understanding exactly what you are trying to accomplish.

Thanks!

-Pete