Part 1: Introduction to Python Statements Video Script
Audio Voiceover |
Screen Visual |
[Introduction] Python is one of the fastest growing programming languages in the world. This open source, multi-purpose language has a simple, clean, beginner-friendly syntax and allows you to solve complex problems in less time and with fewer lines of codes than other programming languages. | A globe centers on the screen as a cloud of programming language names such as JavaScript, Java, C#, C, C++, Dart, R, Swift, Perl, Kotlin, etc. envelope and swirl around the Earth. Meanwhile, a snake slithers on screen looking puzzled at the swirling mass before tossing the word-engulfed globe off-screen with his head. |
[Statements] Statements are how Python programmers tell the program what to do. There are many different types of statements in the Python programming language. Two of the most basic and useful are Assignment Statements and Conditional Statements. | Snake continues to crawl across the screen leaving the word “Statements” in its wake. The word “Statements” is replaced with a cartoon image of a “To-Do list” that populates with the short bulleted list “Assignment Statements” and “Conditional Statements”. |
[Example] With Assignment Statements, we can assign an object to a name. Let’s say that the temperature outside equals x. Now we can use Conditional Statements to have fun with that variable. If the temperature is above 85 degrees, we want to say “Let’s have ice cream!” so we use an “if” statement and set that condition. If it’s below 85 degrees but above 55 degrees, we want to say “Let’s play frisbee!” so we use an else/if statement, which is combined into the much easier to type “e-l-i-f” statement. If the temperature remains below the 55 degree threshold, we want to say, “Let’s have hot cocoa!” Because our temperature x has met neither of the first two conditions, we can simply use the statement “else” to tell the program the only option remaining. In this case…hot cocoa! | Assignment Statements” enlarges and replaces “To-Do list” image. Below that, “temperature = x” is typed out and remains on-screen the rest of the video, as do each line of code added. “Conditional Statements” replaces “Assignment Statements”. An overheated snake slithers across the bottom of the screen while the following appears below “temperature = x”: if x > 85: print(“Let’s have ice cream!”) A much happier snake slithers across the screen, chasing a frisbee. “else/if” appears below the previous line of code before being scratched out and replaced with: elif x > 55: print(“Let’s play frisbee!”) A snake wearing a scarf slithers across the screen and the final line of code appears: else: print(“Let’s have hot cocoa!”) |
Part 2: Video Learning Assessment
Demonstrate your understanding of how Statements are used in Python.
Python uses simple syntax to perform complex operations, which can be applied to many different kinds of tasks, from data analysis to artificial intelligence to automation. Statements are the nuts and bolts that tell the Python program what to do and when to do it.
In the above example, we used two different types of Python Statements. With Conditional Statements, we set automated responses to a real-world variable that was defined by our Assignment Statement.
Try writing your own set of conditional responses to a real-word variable. Begin with your Assignment Statement. What can you use instead of “temperature”?
temperature = x
Following that, begin your Conditional Statements. Replace the numbers and statements with your own scenario. If you want to extend beyond three statements, use multiple “elif” statements to refine the options before ending with “else”.
if x > 85:
print(“Whatever you want to say!”)
elif x > 55:
print(“Say something else.”)
else:
print(“When all else fails, say this.”)
Quiz Question:
Statements in the Python programming language can ____________. (choose all that apply)
- Be used to assign an object to a name.
- Be used to tell the programmer what to do.
- Be written in fewer lines of code than other programming languages.
- Only be Assignment or Conditional.