Join the most intelligent community of young coders. Browse, save & play with codes to understand how they work, and code your own ideas to earn badges & scholarships.

# Break the Code

## posted 9 days ago

if-else

HI This code is by Chithranjan Its a game called Break the code Pls react if you liked it β€ππ₯

print("Hello there Programmers ππ")
print("Its Chithranjan")
name=input("Enter you name")
print(f"Hi {name} Today I got a game for you called Break the code")
print(" the rule is Each of us will try to guess each other's code, one chance for both of us to guess each other's code and the code should only be of 2 digits:")
print("alright lets start")
print("Try guessing mine first")

print("-------------------------Round 1-------------------------")
if try1 == '75':
print("Yes you are correct let me try yours")
else:
print("No its not right let me try yours")

print("If I am right type small 'y' and press enter if wrong type small 'n' and press enter")
_try_1=input("is it 99?")
if _try_1 == 'y':
print("HurraH")
else :
print("oh I am wrong")

print("So lets see who is the winner")
points1 = 0
points2 = 0
if try1 == '75':
points2 = points2+1

if _try_1 == 'y':
points1 = points1+1

if points1>points2:
print("I win, better luck next time")
if points1<points2:
print("You win congratulations")
if points1 == points2:
print("Its a draw")

print("Please react to my codeβ€π₯π")

# Tic-Tac-Toe (With GUI)

## posted 19 days ago

Tic-Tac-Toe using tkinter GUI library. Fun game for 2 people to play.βββββββββ

from tkinter import *

from tkinter import messagebox

count = 0

board = [["", "", ""], ["", "", ""], ["", "", ""]]

def Quit():

global t

message = messagebox.askquestion("Are You Sure U Wanna Quit This Game ?")

if message == "yes":

t.destroy()

def Destruct():

global t, winnerWindow

t.destroy()

winnerWindow.destroy()

def DisplayWinner(player):

global winnerWindow

winnerWindow = Tk()

winnerWindow.title(f"WOHOOOOO!!")

winnerWindow.configure(bg = "Black")

textLabel = Label(winnerWindow, text = f"The Winner Is :").grid(row = 0, column = 1)

textLabel2 = Label(winnerWindow, text = f"Player {player}").grid(row = 1, column = 1)

quitButton = Button(winnerWindow, text = "Ok", font = ("Helvetica",10, "bold"), command = Destruct)

quitButton.grid(row = 2, column = 2)

def PutValue(button, boardRow, boardCol):

global count

if button["text"] == "":

if count % 2 == 0:

button["text"] = "X"

board[boardRow][boardCol] = "X"

label1 = Label(t, text = "Player-2(O)", height = 3, font = ("Helvetica",10, "bold")).grid(row=0,column=0)

CheckWinner("X")

else:

button["text"] = "O"

board[boardRow][boardCol] = "O"

label1 = Label(t, text = "Player-1(X)", height = 3, font = ("Helvetica",10, "bold")).grid(row=0,column=0)

CheckWinner("O")

count = count + 1

print(board)

else:

def CheckWinner(player):

global board,count

if (board[0][0] == player and board[0][1] == player and board[0][2] == player) or (board[1][0] == player and board[1][1] == player and board[1][2] == player) or (board[2][0] == player and board[2][1] == player and board[2][2] == player) or (board[0][0] == player and board[1][0] == player and board[2][0] == player) or (board[0][1] == player and board[1][1] == player and board[2][1] == player) or (board[0][2] == player and board[1][2] == player and board[2][2] == player) or (board[0][0] == player and board[1][1] == player and board[2][2] == player) or (board[0][2] == player and board[1][1] == player and board[2][0] == player):

DisplayWinner(player)

def TicTacToeGUI():

global t

t = Tk()

t.title("Tic Tac Toe")

t.configure(bg = "#DEDEDE")

#Player Label

label1 = Label(t, text = "Player-1(X)", height = 3, font = ("Helvetica",10, "bold"))

label1.grid(row=0,column=0)

#Quit Button

quitButton = Button(t, text = "Quit", font = ("Helvetica",10, "bold"), command = Quit)

quitButton.grid(row = 0, column = 2)

#Grid Buttons

b1 = Button(t, text = "", height = 4, width = 6, font = ("Helvetica",10, "bold"), command = lambda : PutValue(b1, 0, 0), bg = "Black", activebackground = "White", fg = "White")

b1.grid(row = 2, column = 0)

b2 = Button(t, text = "", height = 4, width = 6, font = ("Helvetica",10, "bold"), command = lambda : PutValue(b2, 0, 1), bg = "Black", activebackground = "White", fg = "White")

b2.grid(row = 2, column = 1)

b3 = Button(t, text = "", height = 4, width = 6, font = ("Helvetica",10, "bold"), command = lambda : PutValue(b3, 0, 2), bg = "Black", activebackground = "White", fg = "White")

b3.grid(row = 2, column = 2)

b4 = Button(t, text = "", height = 4, width = 6, font = ("Helvetica",10, "bold"), command = lambda : PutValue(b4, 1, 0), bg = "Black", activebackground = "White", fg = "White")

b4.grid(row = 3, column = 0)

b5 = Button(t, text = "", height = 4, width = 6, font = ("Helvetica",10, "bold"), command = lambda : PutValue(b5, 1, 1), bg = "Black", activebackground = "White", fg = "White")

b5.grid(row = 3, column = 1)

b6 = Button(t, text = "", height = 4, width = 6, font = ("Helvetica",10, "bold"), command = lambda : PutValue(b6, 1, 2), bg = "Black", activebackground = "White", fg = "White")

b6.grid(row = 3, column = 2)

b7 = Button(t, text = "", height = 4, width = 6, font = ("Helvetica",10, "bold"), command = lambda : PutValue(b7, 2, 0), bg = "Black", activebackground = "White", fg = "White")

b7.grid(row = 4, column = 0)

b8 = Button(t, text = "", height = 4, width = 6, font = ("Helvetica",10, "bold"), command = lambda : PutValue(b8, 2, 1), bg = "Black", activebackground = "White", fg = "White")

b8.grid(row = 4, column = 1)

b9 = Button(t, text = "", height = 4, width = 6, font = ("Helvetica",10, "bold"), command = lambda : PutValue(b9, 2, 2), bg = "Black", activebackground = "White", fg = "White")

b9.grid(row = 4, column = 2)

TicTacToeGUI()

# Earth and moon rotation and revolution code

## posted 9 days ago

class
function

from turtle import Shape, Turtle, mainloop, Vec2D as Vec

G = 8

class GravSys(object):

def __init__(self):

self.planets = []

self.t = 0

self.dt = 0.01

def init(self):

for p in self.planets:

p.init()

def start(self):

for i in range(10000):

self.t += self.dt

for p in self.planets:

p.step()

class Star(Turtle):

def __init__(self, m, x, v, gravSys, shape):

Turtle.__init__(self, shape=shape)

self.penup()

self.m = m

self.setpos(x)

self.v = v

gravSys.planets.append(self)

self.gravSys = gravSys

self.resizemode("user")

self.pendown()

def init(self):

dt = self.gravSys.dt

self.a = self.acc()

self.v = self.v + 0.5*dt*self.a

def acc(self):

a = Vec(0,0)

for planet in self.gravSys.planets:

if planet != self:

v = planet.pos()-self.pos()

a += (G*planet.m/abs(v)**3)*v

return a

def step(self):

dt = self.gravSys.dt

self.setpos(self.pos() + dt*self.v)

if self.gravSys.planets.index(self) != 0:

self.a = self.acc()

self.v = self.v + dt*self.a

## create compound yellow/blue turtleshape for planets

def main():

s = Turtle()

s.reset()

s.getscreen().tracer(0,0)

s.ht()

s.pu()

s.fd(6)

s.lt(90)

s.begin_poly()

s.circle(6, 180)

s.end_poly()

m1 = s.get_poly()

s.begin_poly()

s.circle(6,180)

s.end_poly()

m2 = s.get_poly()

planetshape = Shape("compound")

s.getscreen().register_shape("planet", planetshape)

s.getscreen().tracer(1,0)

## setup gravitational system

gs = GravSys()

sun = Star(1000000, Vec(0,0), Vec(0,-2.5), gs, "circle")

sun.color("yellow")

sun.shapesize(1.8)

sun.pu()

earth = Star(12500, Vec(210,0), Vec(0,195), gs, "planet")

earth.pencolor("green")

earth.shapesize(0.8)

moon = Star(1, Vec(220,0), Vec(0,295), gs, "planet")

moon.pencolor("blue")

moon.shapesize(0.5)

gs.init()

gs.start()

return "Done!"

if __name__ == '__main__':

main()

mainloop()

# Calculator

## posted 19 days ago

A calculator which can help you with a lot of types of calculations.

#Calculator
#Choices
choice = input("""Please Enter One Of The Following Operations As Per You Want:
- Subtract
- Multiply
- Divide
- Modulus""")
print(f"You Chose {choice}")

output = 0
num1 = 0
num2 = 0
num1 = int(input(f"Enter The Number 1"))
num2 = int(input(f"Enter The Number 2"))
output = (num1 + num2)
print(f"The Output Is {round(output, 3)}, Good Day Ahead :)")
elif choice == "Subtract":
num1 = int(input(f"Enter The Number 1"))
num2 = int(input(f"Enter The Number 2"))
output = (num1 - num2)
print(f"The Output Is {round(output, 3)}, Good Day Ahead :)")
elif choice == "Multiply":
num1 = int(input(f"Enter The Number 1"))
num2 = int(input(f"Enter The Number 2"))
output = (num1 * num2)
print(f"The Output Is {round(output, 3)}, Good Day Ahead :)")
elif choice == "Divide":
num1 = int(input(f"Enter The Number 1"))
num2 = int(input(f"Enter The Number 2"))
output = (num1 / num2)
print(f"The Output Is {round(output, 3)}, Good Day Ahead :)")
elif choice == "Modulus":
num1 = int(input(f"Enter The Number 1"))
num2 = int(input(f"Enter The Number 2"))
output = (num1 % num2)
print(f"The Output Is {round(output, 3)}, Good Day Ahead :)")
else:
print("Please Enter A Valid Input :)")

# CopyCat Bot

## posted 9 days ago

while loop

It will copy whatever you type! and it's very simple!

print("Let's talk! Enter 'quit' to exit...")

while True:

user = input("You: ")

print(f"Bot: {user}")

if user == 'quit':

break

# Sudoku

## posted 17 days ago

games
function
elif

rows = [
["5", "3", " ", " ", "7", " ", " ", " ", " "],
["6", " ", " ", "1", "9", "5", " ", " ", " "],
[" ", "9", "8", " ", " ", " ", " ", "6", " "],
["8", " ", " ", " ", "6", " ", " ", " ", "3"],
["4", " ", " ", "8", " ", "3", " ", " ", "1"],
["7", " ", " ", " ", "2", " ", " ", " ", "6"],
[" ", "6", " ", " ", " ", " ", "2", "8", " "],
[" ", " ", " ", "4", "1", "9", " ", " ", "5"],
[" ", " ", " ", " ", "8", " ", " ", "7", "9"]]

initialData = [
["5", "3", "7"],
["6", "1", "9", "5"],
["9", "8", "6"],
["8", "6", "3"],
["4", "8", "3", "1"],
["7", "2", "6"],
["6", "2", "8"],
["4", "1", "9", "5"],
["8", "7", "9"]]

squareData = [
["5", "3", "6", "9", "8"],
["7", "1", "9", "5"],
["6"],
["8", "4", "7"],
["6", "8", "3", "2"],
["3", "1", "6"],
["6"],
["4", "1", "9", "8"],
["2", '8', "5", "7", "9"]]

count = 30

def displayBoard():
global rows

print("=======================================")

for i in range(1, 10):
for j in range(1, 10):
if j % 3 == 0:
print(" " + rows[i - 1][j - 1], end = " ||")
else:
print(" " + rows[i - 1][j - 1], end = " |")
print()
if i % 3 == 0:
print("=======================================")
else:
print("---------------------------------------")

def play():
global count, rows

displayBoard()
print("\n")

while count < 81:
command = input("Press A to add number and E to erase number: ")
print("\n")

if command == "A":
r = int(input("Enter Row: "))
c = int(input("Enter column: "))

if rows[r - 1][c - 1] == " ":
number = input("Enter Number: ")
print("\n")
check_ = check(number, r, c)

if check_ == True:
rows[r - 1][c - 1] = number
update(number, r, c)
count += 1
displayBoard()
print("\n")

else:
print("Number Invalid.")
print("\n")

else:
print("Position Occupied.")
print("\n")

elif command == "E":
r = int(input("Enter Row: "))
c = int(input("Enter column: "))
print("\n")

number_ = rows[r - 1][c - 1]

if rows[r - 1][c - 1] == " ":
print("Can not erase empty block.")
print("\n")
elif number_ in initialData[r - 1]:
print("Can not delete initial data.")
print("\n")

else:
rows[r - 1][c - 1] = " "
count -= 1
displayBoard()
print("\n")

else:
print("There is no such command.")
print("\n")

def check(input_, r, c):
for x in rows[r - 1]:
if x == input_:
return False
for x in range(0, 9):
if rows[x][c - 1] == input_:
return False
square = int((r - 1)/3)
square2 = int((c - 1)/3)
index_ = square * 3 + square2
for x in squareData[index_]:
if x == input_:
return False
return True

def update(input_, r, c):
square = int((r - 1)/3)
square2 = int((c - 1)/3)
index_ = square * 3 + square2
squareData[index_].append(input_)

play()

## posted 9 days ago

if-else

You have to think about a number, and it will guess the result.

dialogue_1 = "Think of any number beetween 1 to 10"
dialogue_2 = "Now Multiply it by 2"
dialogue_3 = "Now add number 4 to it"
dialogue_4 = "Now divide the total by 2"
dialogue_5 = "Now subtract the orginal number from the result"
dialogue_6 = "if I am right then the answer should be number 2"
print(dialogue_1)
dialogue_YN = str(input("Write 'yes' when done:"))
if dialogue_YN == "yes":
print(dialogue_2)
else:
dialogue_YN = str(input("Write 'yes' when done:"))
dialogue_YN = str(input("Write 'yes' when done:"))
print(dialogue_3)
dialogue_YN = str(input("Write 'yes' when done:"))
if dialogue_YN == "yes":
print(dialogue_4)
else:
dialogue_YN = str(input("Write 'yes' when done:"))
dialogue_YN = str(input("Write 'yes' when done:"))
if dialogue_YN == "yes":
print(dialogue_5)
else:
dialogue_YN = str(input("Write 'yes' when done:"))
dialogue_YN = str(input("Write 'yes' when done:"))
if dialogue_YN == "yes":
print(dialogue_6)
else:
dialogue_YN = str(input("Write 'yes' when done:"))
dialogue_YN = str(input("Write 'yes' if i am correct:"))
if dialogue_YN == "yes":
print("I am a Genius!!!")
else:
print("Please check your calculation again!")

# Currency Converter

## posted 17 days ago

utilities
tkinter

This currency converter only functions as per USD to INR.

import tkinter as tk

main_screen = tk.Tk()

main_screen.title("Currency Converter")

#Canvas

main_screen_canvas = tk.Canvas(main_screen, width = 380, height = 350, bg="palevioletred")

main_screen_canvas.pack()

#Text Entry Field

currency_USD_label = tk.Label(main_screen, text='USD :')

currency_USD_label.config(font=('helvetica', 14, 'bold', 'underline' ),bg='palevioletred',fg='white')

#USD Amount to be converted

currency_INR_entry = tk.Entry(main_screen, width = 10, font=('helvetica', 10, 'bold'),bg='SkyBlue4',fg='white')

hack = tk.StringVar()

currency_dollar_converted_entry = tk.Entry(main_screen, width = 10, font=('helvetica', 10, 'bold'),bg='SkyBlue4',fg='white', textvariable = hack)

#Create window puts everything onto the canvas

main_screen_canvas.create_window(140, 100, window=currency_USD_label)

main_screen_canvas.create_window(200, 100, window=currency_INR_entry)

main_screen_canvas.create_window(210, 300, window=currency_dollar_converted_entry)

#Function to convert our currency

def conversion():

USD = currency_INR_entry.get()

INR_Converted = float(USD)*73.91

hack.set(str(INR_Converted))

#convert_button which when clicked, makes the function conversion run

currency_dollar_label = tk.Label(main_screen,text="INR :")

currency_dollar_label.config(font=('', 14, 'bold', 'underline'),bg='palevioletred',fg='white')

main_screen_canvas.create_window(120, 300, window=currency_dollar_label)

convert_button = tk.Button(text='Convert', command=conversion, font=('helvetica', 10, 'bold'),bg='navy blue',fg='white')

main_screen_canvas.create_window(200, 200, window=convert_button)

main_screen.mainloop()

# English Dictionary

## posted 9 days ago

dictionary

This is an English Dictionary. You have to run it on editors like VS Code or PyCharm. To run it you need to have PyDictionary installed [pip install PyDictionary].

from pydictionary import *

from time import *

dict = PyDictionary()

print ("Welcome to the Dictionary made by Neil")

sleep (0.5)

word = input ("Type your word: ")

sleep (0.1)

dictionary = dict.meaning(word)

print("The meaning of the word", word, "is :")

print (dictionary)

quit()

# Alarm Clock

## posted 9 days ago

utilities
function

NOTE - THIS CODE ONLY WORKS ON EDITORS LIKE VS CODE AND IT NEEDS TKINTER AND PLAYSOUND LIBARY TO RUN COMMAND TO INSTALL TKINTER ("pip install tkinter") COMMAND TO INSTALL PLAYSOUND ("pip install playsound")

Note='''NOTE - THIS CODE ONLY WORKS ON EDITORS LIKE VS CODE AND IT NEEDS TKINTER AND PLAYSOUND LIBARY TO RUN

COMMAND TO INSTALL TKINTER ("pip install tkinter")

COMMAND TO INSTALL PLAYSOUND ("pip install playsound")'''

from tkinter import *

import datetime

import time

from playsound import playsound

# Create Object

root = Tk()

# Set geometry

root.geometry("400x200")

def play():

playsound('sound.mp3')

t1.start()

def alarm():

# Infintite Loop

while True:

# Set Alarm

set_alarm_time = f"{hour.get()}:{minute.get()}:{second.get()}"

# Wait for one seconds

time.sleep(1)

# Get current time

current_time = datetime.datetime.now().strftime("%H:%M:%S")

print(current_time,set_alarm_time)

# Check whether set alarm is equal to current time or not

if current_time == set_alarm_time:

print("Time to Wake up")

# Playing sound

play()

Label(root,text="Set Time",font=("Helvetica 15 bold")).pack()

frame = Frame(root)

frame.pack()

hour = StringVar(root)

hours = ('00', '01', '02', '03', '04', '05', '06', '07',

'08', '09', '10', '11', '12', '13', '14', '15',

'16', '17', '18', '19', '20', '21', '22', '23', '24'

)

hour.set(hours[0])

hrs.pack(side=LEFT)

minute = StringVar(root)

minutes = ('00', '01', '02', '03', '04', '05', '06', '07',

'08', '09', '10', '11', '12', '13', '14', '15',

'16', '17', '18', '19', '20', '21', '22', '23',

'24', '25', '26', '27', '28', '29', '30', '31',

'32', '33', '34', '35', '36', '37', '38', '39',

'40', '41', '42', '43', '44', '45', '46', '47',

'48', '49', '50', '51', '52', '53', '54', '55',

'56', '57', '58', '59', '60')

minute.set(minutes[0])

mins.pack(side=LEFT)

second = StringVar(root)

seconds = ('00', '01', '02', '03', '04', '05', '06', '07',

'08', '09', '10', '11', '12', '13', '14', '15',

'16', '17', '18', '19', '20', '21', '22', '23',

'24', '25', '26', '27', '28', '29', '30', '31',

'32', '33', '34', '35', '36', '37', '38', '39',

'40', '41', '42', '43', '44', '45', '46', '47',

'48', '49', '50', '51', '52', '53', '54', '55',

'56', '57', '58', '59', '60')

second.set(seconds[0])

root.mainloop()