Simple Chat App CLI Project in Python

← Back to Projects

Simple Chat App in Python (Beginner Console Project)

A chat application is a great beginner project to understand how programs handle user input and continuous execution. In this project, you’ll build a simple command-line chat app in Python that simulates a conversation between two users using the terminal.

This project is designed purely for learning purposes and does not involve networking, internet communication, or real-time messaging servers.

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 This Chat App Works:

The program runs in a continuous loop and alternates between two users. Each user types a message, and the conversation continues until one user enters the letter q to quit the chat.

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.



What You Will Learn From This Project

  • How to use Python’s input() function effectively
  • How infinite loops work in Python
  • How to control program flow using conditions
  • How to build interactive command-line programs
  • Basic simulation of user interaction

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()





Project Limitations

This is a simulated chat application that runs entirely in the terminal. It does not support networking, multiple machines, or real-time communication.

To build a real chat application, you would need technologies such as sockets, web frameworks, or messaging servers.


Ideas to Extend This Project

  • Store chat history in a file
  • Add timestamps to each message
  • Convert it into a socket-based chat app
  • Build a GUI version using Tkinter
  • Add usernames dynamically instead of fixed labels

Frequently Asked Questions


Is this a real chat application?

No. This project only simulates a chat using terminal input and output.

Is this suitable for beginners?

Yes. This project is ideal for beginners learning loops and user input.

Does this app use the internet?

No. It runs completely offline inside the console.



← Back to Projects