📄 Working Code
The exact code from every episode. Click Copy, paste it into the editor or your own Python, and press Run.
From your first print() to a full Tic-Tac-Toe game.
print("My name is Coderboy")
name = "Maya"
print(name)
city = "Dubai"
print(city + 1)
apples = 5
oranges = 3
print(apples + oranges)
print((2 + 3) * 4)
name = input("What is your name: ")
print("Hello", name)
name = input("What is your name: ")
age = int(input("How old are you: "))
print("Hi", name, "next year you will be", age + 1)
age = 5
if age >= 9:
print("Old enough to code!")
print(5 == 5)
print(5 != 5)
print(9 > 4)
print(8 < 2)
print(9 >= 9)
print(7 <= 4)
for i in range(5):
print(i)
for i in range(3):
print("for", i)
n = 3
while n > 0:
print("while", n)
n = n - 1
print(len("Coderboy"))
fruits = ["apple", "banana", "cherry", "date"]
for fruit in fruits:
print(fruit)
import random
colors = ["red", "blue", "green"]
print(random.choice(colors))
name = input("What is your name? ")
age = int(input("How old are you? "))
color = input("What is your favorite color? ")
if age < 7:
print("You are still very young")
elif age < 10:
print("You are a young coder")
else:
print("You are growing fast")
print("Hello " + name + "!")
print("Your favorite color is " + color + "!")
import random
secret = random.randint(1, 10)
guess = int(input("Pick a number from 1 to 10: "))
if guess == secret:
print("Correct! The number was", secret)
elif guess < secret:
print("Too low. The number was", secret)
else:
print("Too high. The number was", secret)
import random
choices = ["rock", "paper", "scissors"]
computer = random.choice(choices)
user = input("rock, paper, or scissors? ")
if user == computer:
print("Tie! Both chose", computer)
elif (user == "rock" and computer == "scissors") or \
(user == "paper" and computer == "rock") or \
(user == "scissors" and computer == "paper"):
print("You win! Computer chose", computer)
else:
print("Computer wins! It chose", computer)
name = input("What is your name? ")
animal = input("A funny animal? ")
place = input("A place? ")
verb = input("A verb ending in -ing? ")
print("One day, " + name + " went to " + place + " and started " + verb + " with a " + animal + ".")
a = int(input("First number? "))
b = int(input("Second number? "))
op = input("Operation (plus, minus, times, divide)? ")
if op == "plus":
print(a + b)
elif op == "minus":
print(a - b)
elif op == "times":
print(a * b)
elif op == "divide":
print(a / b)
else:
print("Unknown operation")
n = int(input("Which table? "))
for i in range(1, 11):
print(n, "x", i, "=", n * i)
questions = [
["How many legs does a dog have? ", "4"],
["What sound does a cat make? ", "meow"],
["What is a baby sheep called? ", "lamb"],
]
score = 0
for item in questions:
answer = input(item[0])
if answer == item[1]:
print("Correct!")
score = score + 1
else:
print("Wrong. The answer was", item[1])
print("Your score is", score, "out of 3")
password = input("Type a password: ")
if len(password) < 5:
print("Very weak")
elif len(password) < 8:
print("Okay")
else:
print("Strong password")
board = [" "] * 9
def mark(i):
return board[i] if board[i] != " " else str(i + 1)
def show():
print(" TIC TAC TOE")
print()
for row in range(3):
a, b, c = mark(row*3), mark(row*3+1), mark(row*3+2)
print(" " + a + " | " + b + " | " + c)
if row < 2:
print(" ---+---+---")
print()
def clear():
print("\n" * 30)
WIN_LINES = [
[0,1,2], [3,4,5], [6,7,8],
[0,3,6], [1,4,7], [2,5,8],
[0,4,8], [2,4,6],
]
player = "X"
for turn in range(9):
clear()
show()
cell = int(input("Player " + player + ", choose 1-9: ")) - 1
board[cell] = player
won = False
for line in WIN_LINES:
if board[line[0]] == board[line[1]] == board[line[2]] != " ":
clear()
show()
print(" Player " + player + " wins!")
won = True
break
if won:
break
player = "O" if player == "X" else "X"
else:
clear()
show()
print(" It's a tie!")