Untitled
unknown
plain_text
8 months ago
1.1 kB
5
Indexable
# Simple CodeHS Program with Loops, Conditionals, and Colors
def print_pattern(color):
"""
Prints a simple pattern with the chosen color.
"""
for i in range(5): # For loop to print a pattern
print(f"{color} * " * 5)
def count_down():
"""
Uses a while loop to count down from 5 to 1.
"""
num = 5
while num > 0:
print(f"Countdown: {num}")
num -= 1
def main():
"""
Main function to run the program.
"""
# Ask user for their favorite color
user_color = input("Enter your favorite color (red, blue, green): ").lower()
# Conditional statement to validate color choice
if user_color not in ["red", "blue", "green"]:
print("Invalid color! Defaulting to blue.")
user_color = "blue"
# Print a pattern with the chosen color
print_pattern(user_color)
# Call function to count down
count_down()
# Final message
print(f"Program finished! Your color was {user_color}.")
# Run the program
main()
Editor is loading...
Leave a Comment