Python Playground

Site Builder

Explore and run Python code directly in your browser

Code Editor

How to use this bot:

  • Type normal messages to chat
  • Type 'train' to teach the bot new responses
  • Type 'quit' to end the session
  • The bot saves everything you teach it!

Output

Your output will appear here...

Example Snippets

Fibonacci Sequence

def fib(n):
  if n <= 1:
    return n
  return fib(n-1) + fib(n-2)

# Print first 10 Fibonacci numbers
for i in range(10):
  print(fib(i))

List Comprehension

# Squares of even numbers
numbers = [1, 2, 3, 4, 5, 6]
squares = [x**2 for x in numbers if x % 2 == 0]

print(squares) # Output: [4, 16, 36]

API Request

import requests

# Fetch data from JSONPlaceholder API
response = requests.get("https://jsonplaceholder.typicode.com/todos/1")
data = response.json()

print("Todo:", data["title"])
print("Completed:", data["completed"])