Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Practice Input and Output in Python!
You have completed Practice Input and Output in Python!
Preview
Let's get things figured out!
Learn more
- If you are looking to learn more about input, output, and variables, we cover that in the course Python Basics. See you there!
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
Well hello there, Craig here.
0:09
How's it going?
0:11
In this workshop, we're gonna practice
using some of those python muscles that
0:12
you've been building up.
0:16
When you're just getting
started with the language,
0:18
sometimes it's hard to find a way to apply
the skills that you've been learning.
0:19
It's hard to see how the pieces that
you've been picking up all snap together
0:24
to form a program.
0:27
Now I'm going to assume for this practice
session, that you know how to use
0:28
variables, take input from a user and
output things to the screen.
0:32
If you don't,
please check the teacher's notes for
0:36
where you can learn those things.
0:39
Believe it or not, but
with just those skills, input, output, and
0:41
variables, you can write
a pretty fun game.
0:45
Now, I'm not sure if you've
done one of these before, but
0:48
Mad Libs has been declared
the world's best word game.
0:53
The way it works is this.
0:57
There's two players, and
one player has a page like this.
0:59
And see how it has blanks that are labeled
with different parts of speech like
1:02
a noun, an adjective, or a verb?
1:05
The first player prompts
the second player for
1:07
words that match those parts of speech and
fills in the blanks with their answers.
1:10
Then the first player reads
the results aloud and hilarity ensues.
1:14
So we're gonna do it.
1:19
We're gonna build MadLibs in Python.
1:20
So let's go back to the workspace.
1:23
Go ahead and launch this and you will see
here I have a file called madlibs.py.
1:24
So I'm gonna open that up.
1:28
And you'll notice here that
I've made a template for us.
1:31
Something that you might not have
encountered yet are these pound signs or
1:35
hashtags, as the kids
are calling them these days.
1:39
What this does is this is a comment, and
1:42
this tells Python to ignore all of
the characters on the line and after it.
1:44
So what we can do is we can use this
to write English, just like I did here.
1:48
It's a way to be able to communicate
to readers of your code.
1:54
You'll end up leaning on these
quite a bit in the future.
1:59
Comments can also be used to make note
of things that you'd like to do later,
2:02
sort of like a to do list.
2:06
And typically the way that you do it,
2:08
kinda the format that's come
about is this to do, in all caps.
2:09
TODO colon and then what it is.
2:13
It's kinda like a standard.
2:15
So I've left some to do's for you to do.
2:18
But first off, I'd like you to prompt
the user for the various parts of speech,
2:22
like the verb and
the noun and the adjective.
2:27
And then store each of
the responses in a variable.
2:32
And then the second to do,
I would like you to output
2:35
that template with the words
that the user just filled out.
2:40
Got it?
2:44
Don't worry, you got this.
2:45
You have all the skills that you need to
achieve this, and it's totally fine for
2:47
this to be a bit of a struggle.
2:52
It's kinda like no pain no gain,
but for your brain.
2:53
So in the next video I'll
show you how I did it.
2:57
In fact, you know what?
3:00
I've already done the practice, so
3:02
let me show you what my final product
looks like so you can try to recreate it.
3:04
So here, I'm gonna jump over to mine.
3:07
I'm not going to show you my code,
nice try.
3:09
So say python and
the name of that program is madlibs.py.
3:12
So this is what it looks
like when it runs.
3:15
So it says, please enter a verb.
3:17
Now remember I don't know
what that template is.
3:18
So dance, I don't know.
3:20
Enter a noun, let's see, dinosaur.
3:23
That's a good noun.
3:25
And an adjective.
3:27
How about wacky?
3:28
I enjoy practice, I find it helps
me to dance better, I wish.
3:30
Without practice,
my dinosaur probably wouldn't even work.
3:34
My codes gonna get more
wacky every single day.
3:36
See, fun, right.
3:39
All right, so you can do this, right?
3:41
And again, don't beat yourself
up if you can't quite get it,
3:43
I want you to really give it a try.
3:46
And remember, I'll show you how
I did it in the next video, but
3:48
don't skip ahead, give it a go, you ready?
3:50
You got this.
3:53
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up