Learn programming concepts interactively
# Python Conditionals - Interactive Examples# Learn if/elif/else statements through hands-on practice# === TRAFFIC LIGHT SIMULATOR ===# Example of if/elif/else chainlight_color = "red"if light_color == "red":action = "Stop completely"elif light_color == "yellow":action = "Prepare to stop"else:action = "Go safely"print(f"Traffic light is {light_color}: {action}")# === GRADE CALCULATOR ===# Example of nested if statementsscore = 85if score < 0 or score > 100:grade = "Invalid"message = "Score must be between 0 and 100"else:if score >= 90:grade = "A"message = "Excellent work!"elif score >= 80:grade = "B"message = "Good job!"elif score >= 70:grade = "C"message = "Satisfactory"elif score >= 60:grade = "D"message = "Needs improvement"else:grade = "F"message = "Try again"print(f"Score: {score} → Grade: {grade} ({message})")# === INPUT VALIDATOR ===# Example of boolean conditions and logical operatorsuser_input = "test@example.com"validation_type = "email"if validation_type == "email":# Simple email validationis_valid = "@" in user_input and "." in user_inputelif validation_type == "age":# Age validationtry:age = int(user_input)is_valid = 1 <= age <= 149except ValueError:is_valid = Falseelif validation_type == "password":# Password strength validationis_valid = (len(user_input) >= 8 andany(c.isupper() for c in user_input) andany(c.isdigit() for c in user_input))else:is_valid = Falseprint(f"Input '{user_input}' is {'valid' if is_valid else 'invalid'}")# Key Concepts:# - if/elif/else chains for multiple conditions# - Nested if statements for complex logic# - Boolean operators (and, or, not)# - Comparison operators (==, !=, <, >, <=, >=)# - Membership operators (in, not in)
No operations yet
Start by adding or modifying elements