Test and Clean Up Your Script
00:33 Curiously, the elephant gallops, the mouse whispers upon the incredulous gorilla. So this is working, getting different poems every time, and it’s following the structure that we were intending to create.
00:47 So I think this is all good. What do you think? Did you spot any potential problems in this? Because I know there is one, since I may or may not have left it in there on purpose to make a point.
00:59 But for now, let’s be happy because this is actually the poem that we wanted to create. So I will clean this code up a bit before we then look at how we can still make the code a little bit more safe.
Nice. And then it’s always better to actually return your value from a function, than just print it. I don’t want to have side effects, so I’m just going to return
poem and then down here I’m going to call
print() and pass it
make_poem(), which should have the exact same effect as before.
You can run this script. Every time you run it, you get a different poem. It follows the structure. And you’ve practiced using a bunch of different functions from the
random module and a bunch of different list methods, as well as nested collections here, a tuple with lists nested inside of it, et cetera.
02:52 That’s pretty nice. I want to give you a chance to think about what a potential problem in the script as you have it right now, or as I have it right now, because you probably wrote something else.
Become a Member to join the conversation.