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 Comparisons in Python!
      
    
You have completed Practice Comparisons in Python!
Preview
    
      
  Here's the approach I took to solve this challenge.
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
                      Welcome back, how'd it go?
                      0:00
                    
                    
                      If you weren't able to complete every
to-do item, that's totally fine.
                      0:03
                    
                    
                      Learning new things is hard.
                      0:07
                    
                    
                      Let's walk through how I
handled this challenge.
                      0:09
                    
                    
                      Here's our first TODO.
                      0:13
                    
                    
                      Remember that inputs are string values and
we need our number to be an integer for
                      0:16
                    
                    
                      our math operations.
                      0:21
                    
                    
                      We can do that by passing
the input into the int function.
                      0:22
                    
                    
                      Let's look at our next TODO's here.
                      0:31
                    
                    
                      For the next task, we need to utilize
string formatting and a new line.
                      0:37
                    
                    
                      We can use an escape sequence for
the new line, all right?
                      0:42
                    
                    
                      And we can pass in the name and
                      0:46
                    
                    
                      number variables into the stringFormat
method to get those values to print.
                      0:48
                    
                    
                      So our next TODO here is to define our
variables for is_fizz and is_buzz.
                      1:00
                    
                    
                      So for is_fizz and is_buzz, we want them
to be boolean values, true or false.
                      1:08
                    
                    
                      For is_fizz,
we do the module operator on the number,
                      1:15
                    
                    
                      by 3, and make sure that that equals 0,
which means there's no remainder.
                      1:20
                    
                    
                      For is_buzz we do the same thing but
with 5.
                      1:25
                    
                    
                      Next up is handling all of this if logic.
                      1:30
                    
                    
                      This may have tripped you up a little bit.
                      1:33
                    
                    
                      And honestly,
                      1:35
                    
                    
                      it is something that many developers
struggle with from time to time.
                      1:36
                    
                    
                      But thinking in this fashion early on
in your Python journey helps a ton.
                      1:40
                    
                    
                      Let's think about how if statements
work and what we're trying to do.
                      1:47
                    
                    
                      We need to check a given number for
the various conditions.
                      1:52
                    
                    
                      The thing to remember through the if and
                      1:56
                    
                    
                      elif statements is that it processes
each conditional check in order.
                      1:58
                    
                    
                      If a condition is met, it does what's
inside the checking block and that's it.
                      2:04
                    
                    
                      Therefore, if we start with a check for
just the number 3 or just the number 5,
                      2:09
                    
                    
                      we'll never get to check for
both of these conditions.
                      2:14
                    
                    
                      Therefore, that check needs to come first.
                      2:18
                    
                    
                      So we check if is_fizz and
is_buzz is first.
                      2:22
                    
                    
                      Then we can check the individual
conditions for 3 and
                      2:28
                    
                    
                      5 divisibility and
print out the necessary statements.
                      2:32
                    
                    
                      Finally, if none of
those conditions exist,
                      2:36
                    
                    
                      we can print that our number
isn't fizzy or buzzy.
                      2:40
                    
                    
                      Excellent work completing
this practice session.
                      2:44
                    
                    
                      Thanks for
working through this challenge with me.
                      2:47
                    
                    
                      Until next time, happy coding.
                      2:49
                    
              
        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