top of page

Conditionals, If and While

# ----------- If Statements Forment A----------
print("----------- If Format A ----------")
var_a=2
var_info="Apples" if(var_a==2) else "Peaches"
print(var_info)

# ----------- If Statements Format B----------
print("-------------If Format B----------")
if var_a == 2:
    print("variable is Equal to 2")
elif var_a > 5:
    print("Value if Greater than 5")
else:
    print("Variable is not Equal to 2")

# -------------- While Statement -------------
print("-------------While Format----------")
while var_info=="Apples":
    print("Scotty")
    var_info=123 # -- Loop Escape

#------------- Other Example ---------------------

while True:
    # Code to execute at least once
    user_input = input("Enter Input (or type 'exit' to quit): ")
    if user_input.lower() == "exit":
        break
    print(f"You entered: {user_input}")

bottom of page