Skip to content

Joseph-T-Gordon

A complete log of all recent projects and skills

Menu
  • About me
  • Posts/Projects
  • Resume/Certifications
Menu

Post #36 (Python Programming) – Conditionals in python

Posted on March 20, 2023June 26, 2023 by admin

Python allows you to run code if a certain condition is true, you can also use else and elif as well for alternate conditions. The following code is an example of conditionals. It is also important to note that == checks if two values are equal to each other while = assigns a value to a variable, there is also >, >=, <, <=, !=. All of these symbols are self explanatory except for != which mean not equal to, so if you had “if 1 != 2” then that would return true and the indented code would run.

var = input(“Please list your favorite color:\n”)

if var == “blue”:

print(“Blue is my favorite color as well, reminds me of the ocean”)

elif var == “red”:

print(“I see a lot of passion behind the color red”)

else:

print(“I love the color”, var, “as well”)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

© 2025 Joseph-T-Gordon | Powered by Minimalist Blog WordPress Theme