Posts

Showing posts with the label Week 1

Short-Circuit Evaluation in Python: Behind the Scenes

Welcome to this short tutorial on Short-Circuit Evaluation, an important aspect of Python Boolean operators that will be key for your future in Computer Science. Let’s begin!  👍 🎓  A Quick Recap In the tutorial:  Boolean Expressions and Operators , you learned about truth tables. Here is a quick recap: With the  and  operator, an expression evaluates to  True  only if both operands are  True  (in this case, the operands are expressions that evaluate to a Boolean value). If either one of them evaluates to  False , the entire expression evaluates to  False . For example: >>> 5 > 6 False >>> 7 < 9 True >>> 5 > 6 and 7 < 9 # Equivalent to -> False and True False >>> 5 < 6 True >>> 7 < 9 True >>> 5 < 6 and 7 < 9 # Equivalent to -> True and True True With the  or  operator, an expression evaluates to  True  if ei...

Iterating over the characters in a string: BEHIND THE SCENES!

Image
Welcome! Hi! Welcome to this short tutorial! We will discuss how to iterate over the character in a string, a very important concept for the course and you Computer Science journey. Syntax On the diagram below you can see the  general syntax  for iterating over the  items contained in an iterable  (strings are iterables and their “items” are the individual characters they contain) Ready? Set! Go! Once we start out for loop, the variable we’ve defined to be used in the for loop (in this case,  char ) will be updated on each iteration (see code in the "output" column on the diagram below). What does this mean? When the loop is run first time,  char ’s value will be  H . When the loop runs for the second time,  char ’s value will be  e And so on! The loop will run  as many times as the number of characters in the string  and the variable  char  will update its value wherever you’ve used it inside...

How to read Python's Documentation: BEHIND THE SCENES!

Image
Welcome! Hi! Welcome to this section where we will dive into a “tool” that you will use and learn to love throughout your Computer Science journey and/or career. Let’s say you’ve found the Build-in Python function  round()  and you would to know more about how it works. What do you do? You go to  PYTHON'S DOCUMENTATION! Concept: First of all, let’s start by describing what is Documentation: Importance and First Impressions As you can see, it is extremely important since it tells you how a software (or in this case, a programming language) can be used. At first it may seem daunting and you will find a lot of technical terminology you maybe haven’t heard of next to the information you actually need, but don’t worry, through experience you will learn to determine what is relevant to your needs and what isn’t. Trust me, I’ve been through this and at first I felt like documentation was very intimidating but with practice I learned to love it ...

Control Flow: For Loops, While loops and range() BEHIND THE SCENES!

Image
Welcome to this section on Control Flow! Control flow  is an essential element of programming.  You can build very powerful programs with loops , so let's see how they work behind the scenes, and  how range() works , because you will use it in this course and in your future programming projects. So let's begin! Let's start with WHILE LOOPS: In While loops a block of code will be executed for as long as a condition is met. Every time the block of code is executed, the condition will be checked again, and if it evaluates to True, the code inside the loop runs again, otherwise it exits the loop and continues executing the code below it. When learning loops, a good strategy is to analyze each step and how values change when the code is executed. In this case, we determine if the code will be executed, the values for the variables involved each time the loop runs and what will be printed on each iteration. The value of n is updated every time the loop...

Booleans are integers?!

Image
Hi, Welcome to this short section. We will discuss Booleans and the fact that the fact that they can be used as integers in your code. This is a curious fact and I thought it would be interesting to share it with you! J Let’s get started! You can find the article on Python Documentation under numbers.Integral : https://docs.python.org/release/3.0.1/reference/datamodel.html#the-standard-type-hierarchy Here are some demonstrations in the Shell of how we can compare and operate on True and False as if they were integers 1 and 0 respectively. Hope it helps! If you have any questions, please ask them in the forums, your classmates and Community TAs will always be there to help you! Estefania.