Simple Chat App CLI Project (code) in Python

← Back to Projects

Simple Chat App (CLI) in Python.

About the project: This will be a standalone script that simulates a text-based conversation between two users in your console.

This program will allow you to type messages as "User 1" and "User 2" alternately, seeing the conversation unfold.

How to use this program:

Save the code: Save the code below as a Python file (e.g., chat_app.py).

Run the script: Open your terminal or command prompt, navigate to the directory where you saved the file, and run:


  python chat_app.py
  

The program will prompt you to type messages for "User 1" and "User 2" alternately.

To end the chat, simply type q at either prompt and press Enter.


Project Level: Beginner

You can directly copy the below snippet code with the help of green copy button, paste it and run it in any Python editor you have.

Steps: Follow these steps

Step 1: Copy below code using green 'copy' button.

Step 2: Paste the code on your chosen editor.

Step 3: Save the code with filename and .py extention.

Step 4: Run (Press F5 if using python IDLE)




# simple_chat_app.py

def main():
    """
    Main function to run the Simple Chat App.
    Simulates a conversation between two users in the console.
    """
    print("--- Python Simple Chat App (CLI) ---")
    print("Type your messages below. Type 'q' to quit at any time.")
    print("------------------------------------")

    while True:
        # User 1's turn to type a message
        user1_message = input("User 1: ").strip()

        if user1_message.lower() == 'q':
            print("Chat ended by User 1. Goodbye!")
            break
        
        # User 2's turn to type a message
        user2_message = input("User 2: ").strip()

        if user2_message.lower() == 'q':
            print("Chat ended by User 2. Goodbye!")
            break

# This ensures that main() is called only when the script is executed directly.
if __name__ == "__main__":
    main()