Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Video Player
00:00
00:00
00:00
- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Let's kick out the information gathering stories for this project
This video doesn't have any notes.
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
Okay, so there's a new workspace
attached to this video, and I'd like for
0:00
you to launch it.
0:04
It has a single file in it
called masterticket.py.
0:04
It's not trademarked, is it, masterticket?
0:10
This file has a single constant defined,
TICKET_PRICE.
0:12
$10, that's very reasonable.
0:17
There's also a counter that is
called tickets_remaining, and
0:19
it's been set up to have
100 tickets available.
0:22
Now that's a pretty small and
intimate space.
0:25
Let's say we grab
the first user story here,
0:27
of as a User I should be shown
the number of tickets left remaining so
0:30
I can understand
the importance of buying now.
0:33
I'm gonna put that In Progress.
0:35
So let's flip back over here.
0:38
I'm gonna make a comment for us.
0:43
So we want to output how
many tickets are remaining,
0:46
using the tickets remaining using
the tickets_remaining variable.
0:51
All right, we can do that.
0:59
Here, I'll tell you what.
1:01
I'll pause and
why don't you write this output statement.
1:02
And after you get it, unpause me and
I'll show you my implementation.
1:06
Are you ready?
1:09
Pause me.
1:10
Here's how I did it.
1:12
So, I'm gonna print("There are {}, and
1:15
I'm gonna use string formatting,
tickets remaining.".
1:19
And I'm gonna format and
I pass in the tickets_remaining variable.
1:25
Awesome, well let's flip to Trello.
1:31
We've already got one done.
1:34
This feels pretty amazing, doesn't it?
1:35
Okay, so next step.
1:37
Let's grab this personalized
experienced one.
1:39
I should have a personalized experience so
that I'm welcomed by the brand.
1:42
So I'm gonna move that to In Progress and
okay.
1:46
So to personalize things,
we need to capture our user's name.
1:51
We're gonna need to use it a bit to
make things seem personalized, right?
1:54
So here,
let me make this comment here for us.
1:59
Why is that indenting?
2:03
You know why it's indenting?
2:08
Look at this.
2:09
Look what I forgot.
2:11
You see how that's indenting there?
2:11
What's missing?
2:13
I forgot this.
2:15
There we go.
2:16
[SOUND] All, right, so
I'm going to make a comment.
2:18
So we'll say, Gather the user's name and
2:23
assign it to a new variable.
2:29
Okay, you totally got this.
2:33
Go ahead and pause me, and
after you get it, unpause me, and
2:34
I'll show you how I did it.
2:37
Ready, so here's what I did.
2:40
I came in here and I said,
name = input("What is your name?
2:43
And I left some spaces,
because we know how that feels.
2:49
So we can't really personalize
anything cuz there's nothing here yet.
2:53
So, let's flip back over to the tasks.
2:56
Ooh, here's a good one.
2:58
As a User I should be able to request
a certain amount of tickets and be told
3:00
the total costs so that I could determine
if I want to purchase the tickets.
3:03
We can totally use this
personalization in the prompt.
3:06
That sounds good.
3:10
Let's do that.
3:11
Okay, so let's see.
3:15
We've got three steps here, right?
3:17
So we've got Prompt the user by name and
3:18
ask how many tickets they would like.
3:24
Sounds good, so personalizing it.
3:29
We'll say, hey, Bob.
3:32
How many tickets would you like?
3:34
And then we'll need to
do some calculation.
3:35
So we'll calculate the price.
3:38
What is that?
3:40
That would be the number
of tickets that they want,
3:41
right, multiplied by the price.
3:48
And you should use that ticket
price variable up there.
3:52
And then we will assign
that to a variable.
3:56
And then finally,
4:02
I think we just need enough to
output the price to the screen for
4:04
this story to be done, so
we'll say Output the price to the screen.
4:09
Okay, so there's three tasks there.
4:14
I want you to take them nice and slow.
4:17
You can totally do this.
4:18
If you get stuck along the way, I invite
you to hit up your teammates who are also
4:20
working through this in the community.
4:24
And you can also unpause me and
4:26
I'll give you a warning before
I start the other ones.
4:27
Ready, you got this.
4:30
Pause me.
4:31
Okay so the first thing that
I did was I got num_tickets
4:33
= input("How many tickets would you like,
and
4:39
then I'm gonna put the place
holder with their name in here.
4:44
And then, a couple spaces.
4:50
And let's go ahead an do format, and
then we'll push the name in, okay?
4:52
Close that paren off, awesome.
4:57
Now to calculate the price, and
this might had been tricky,
5:00
this might have caught some of you.
5:02
We first need to make sure
that we have an integer.
5:04
So what I did was I
reassigned num_tickets, so
5:07
I said num_tickets = int(num_tickets).
5:12
So now we have an integer in num_tickets,
is reassigned.
5:17
Okay, and then I calculated the price.
5:23
And that was amount_due.
5:25
And that's equal to
the num_tickets * TICKET_PRICE.
5:28
Okay, how'd you do?
5:35
Hope that coercion didn't trip you up.
5:37
Okay, and finally I output the total
again, using the format method on strings.
5:38
And it doesn't matter that
amount due is an integer,
5:43
it automatically coerces
it to a string for us.
5:46
So, print("The total due is.
5:48
So this is what mine
looks like when it runs.
6:01
Does yours work?
6:05
Let's see, we'll say python masterticket.
6:06
My name is Craig, and
I would like to buy three tickets.
6:14
Total due is 30 bucks, awesome!
6:18
Is yours working, too?
6:21
So let's flip over to Trello,
and we've got both of these done.
6:23
That's a personalized experience.
6:27
We got to remember to keep doing that.
6:29
They seemed really keen on that.
6:30
And they are also able to request
a certain amount of questions, and
6:32
we got told the total cost.
6:35
We are cruising along.
6:37
Let's tackle the next few user
stories right after this quick break.
6:38
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