Python code that prints "Stay mad, haters!" with additional features, including user input for customization and a countdown timer before displaying the message:
```python
import time
from colorama import Fore, Style, init
# Initialize colorama
init(autoreset=True)
def stay_mad_haters(message, color):
print(color + message)
def countdown(seconds):
for i in range(seconds, 0, -1):
print(f"Displaying message in {i} seconds...")
time.sleep(1)
# Example usage
if __name__ == "__main__":
user_message = input("Enter your message (default: 'Stay mad, haters!'): ") or "Stay mad, haters!"
user_color = input("Choose a color (red, green, blue, yellow): ").strip().lower()
color_map = {
"red": Fore.RED,
"green": Fore.GREEN,
"blue": Fore.BLUE,
"yellow": Fore.YELLOW
}
selected_color = color_map.get(user_color, Fore.WHITE) # Default to white if color not found
countdown(5) # Countdown before displaying the message
stay_mad_haters(user_message, selected_color)
```
### Code Breakdown
1. **Imports and Initialization**: The code imports the necessary libraries, including `time` for the countdown and `colorama` for colored text. The `init` function initializes colorama, ensuring that colors reset automatically after each print.
2. **Function Definitions**:
- **stay_mad_haters**: This function takes a message and a color as arguments and prints the message in the specified color.
- **countdown**: This function takes a number of seconds as an argument and counts down to zero, printing a message each second.
3. **User Input**: The code prompts the user to enter a custom message and choose a color. If the user does not provide a message, it defaults to "Stay mad, haters!". The color options include red, green, blue, and yellow.
4. **Color Mapping**: A dictionary maps user-friendly color names to the corresponding `colorama` color codes. If the user inputs an invalid color, the message will be printed in white by default.
5. **Countdown and Message Display**: The program performs a countdown of 5 seconds before displaying the final message in the chosen color.
### Example Usage
When you run this code, it will first ask for a custom message and a color. After a brief countdown, it will display the message in the selected color. This interactive approach not only makes the program more engaging but also allows users to personalize their experience.
This code can be a fun way to express sentiments in a colorful manner, whether for a personal project, a social media post, or just for a laugh among friends. You can further extend this by adding more colors, styles, or even sound effects to enhance the experience!
Comments
Displaying 2 of 2 comments ( View all | Add Comment )
Xx_ranalan_xX
Kiss kiss
Strawb3rryluvr
Thanks for coming back, when the world needed you… heh… you really showed up