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.

# Homework

## posted a month ago

mathematics

print("Welcome to Circle area and circumference calculator!")
print("AREA = "+str(round(area,2))+"\nCIRCUMFERENCE = "+str(round(circumference,2)))

# vowels list

## posted a month ago

if-else

word = 'junainah has lots of vowels'
vowels = ['a','e','i','o','u']
counter = 0
letterlist=list(word)
print(letterlist)

for letter in word:
if letter in vowels:
counter=counter+1

print('No. of Vowels are: ',counter)

# CALCULATOR

## posted 3 months ago

mathematics
elif

print("Welcome to maths operation")
print("You can select any of the maths operation")
print("S - subtraction")
print("M - multiplication")
print("D - division")
print("P - percentage")

choice=input("Choose an option from above list:")

if choice =="M":
a=input("Type your first number for multiplication:")
b=input("Type your second number for multiplication:")
c=int(a)*int(b)
elif choice =="D":
d=input("Type your first numder for Divition:")
e=input("Type your second number for Divition:")
f=int(d)/int(e)
elif choice =="S":
g=input("Type your first number for substaction:")
h=input("Type your second number for sustaction:")
i=int(g)-int(h)
elif choice =="A":
l=int(j)+int(k)
elif choice =="P":
m=input("Type your first number for modulus or percentage")
n=input("Type your second number for modulus or percentage ")
o=int(m)%(n)
else:
print("Invaid Input")

# Temperature converter

## posted 3 months ago

if-else
utilities

print("Hello, and welcome to the temperature converter.")
print("""Type :
( 1 ) -  For  ( Celsius )     -->    ( Fahrenheit )

( 2 ) -  For  ( Fahrenheit )  -->    ( Celsius )

( 3 ) -  For  ( Celsius )     -->    ( Kelvin )

( 4 ) -  For  ( Kelvin )      -->    ( Celsius )

( 5 ) -  For  ( Fahrenheit )  -->    ( Kelvin )

( 6 ) -  For  ( Kelvin )      -->    ( Fahrenheit )\n""")

choice = input()

if choice == "1":
print("Enter the temperature in Celsius : ")
temp = int(input())
temp = temp * 9 / 5 + 32
print("Degrees Fahrenheit : ", int(temp))

elif choice == "2":
print("Enter the temperature in Fahrenheit : ")
temp = int(input())
temp = (temp - 32) * 5 / 9
print("Degrees Celsius : ", int(temp))

elif choice == "3":
print("Enter the temperature in Celsius: ")
temp = int(input())
temp += 273
print("Degrees Kelvin : ", int(temp))

elif choice == "4":
print("Enter the temperature in Kelvin: ")
temp = int(input())
temp -= 273
print("Degrees Celsius : ", int(temp))

elif choice == "5":
print("Enter the temperature in Fahrenheit: ")
temp = int(input())
temp = (temp - 32) * 5 / 9 + 273
print("Degrees Kelvin : ", int(temp))

elif choice == "6":
print("Enter the temperature : ")
temp = int(input())
temp = (temp - 273) * 9 / 5 + 32
print("Degrees Fahrenheit in Kelvin: ", int(temp))

# Math Homework Solver

## posted 3 months ago

mathematics
while loop

print("MathHomework.py")

# Ask the user to enter a math problem

problem = input("Enter a math problem, or 'q' to quit: ")

# Keep going until the user enters 'q' to quit

while (problem != "q"):

# Show the problem, and the answer using eval()

print("The answer to ", problem, "is:", eval(problem) )

# Ask for another math problem

problem = input("Enter another math problem, or 'q' to quit: ")

# This while loop will keep going until you enter 'q' to quit

# Currency converter

## posted 3 months ago

if-else
utilities

Hi Python friends! So, today I made a currency converter... Where I can convert US Dollar to Indian Rupee and Indian Rupee to US Dollar... Try this code.... It is super fun... Bye!!!

print("Hello, and welcome to the currency converter.")
print("""Type:
(1) - For ( US Dollar )   -->   ( Indian Rupee )

(2) - For ( Indian Rupee )   -->   ( US Dollar )\n""")

choice = input()

if choice == "1":
print("Enter the currency in US Dollar : ")
curr = int(input())
curr = curr * 74.42
print("Currency Indian Rupee : ", int(curr))

elif choice == "2":
print("Enter the currency in Indian Rupee : ")
curr = int(input())
curr = curr * 0.013
print("Currency US Dollar : ", int(curr))

# Animal Quiz

## posted 3 months ago

elif
if-else

a=input("please enter your name:")
print(f'''hello {a}!
Welcome to the quizer where
you can test your knowledge on animals''')

b=input("""please type start in small letters to start
the quiz.""")
if b=="start":
print("What is the animal with the longest tail?(Please type all answers in small letters.)")
c=input()
if c=="spider monkey":
else:
print("What is the fastest bird?")
d=input()
if d=="Peregrine falcon":
else:
print("What is the most popular bird?")
e=input()
if e=="chicken":
else:
print("What is the biggest animal in the world?")
f=input()
if f=="blue whale":
else:
print("How much would you rate this code")
g=input()
if g=="5 stars":
else:
print("wrong answer!")

# Tic Tac Toe, Player VS AI

## posted 4 months ago

'''
TIC TAC TOE
PLAYER VS COMPUTER
'''

import random

player_1 = input("Enter player 1 name : ")
player_2 = 'James'
print(f'Player 2 name(pc) is {player_2}')
game = True
winner = "none"
count = 0
slots = [1,2,3,4,5,6,7,8,9]
mode = input('Which mode do you want to play in Easy, Medium or Hard(unbeatable) : ')

#assign characters "x or o"
player1_character = input(f"{player_1} what character do you want (x or o) : ")
if player1_character == "x":
player2_character = "o"
else:
player2_character = "x"
player1_character = "o"

#who will go first
whoWillGoFirst = random.randint(1,2)

if whoWillGoFirst == 1:
print(f"{player_1} will go first\n{player_2} will go second")
else:
print(f"{player_2} will go first\n{player_1} will go second")

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

#making the board
def board_game():
print('   |   |')
print(' ' + board[0] + ' | ' + board[1] + ' | ' + board[2])
print('   |   |')
print('-----------')
print('   |   |')
print(' ' + board[3] + ' | ' + board[4] + ' | ' + board[5])
print('   |   |')
print('-----------')
print('   |   |')
print(' ' + board[6] + ' | ' + board[7] + ' | ' + board[8])
print('   |   |')

# making functions for player 1 turn and player 2
def player1_turn():
position = int(input(f"{player_1} which position do you want to place your character (1 to 9)"))
position = position - 1
if board[position] == " ":
board.pop(position)
board.insert(position,player1_character)
print("the board has been updated")
board_game()
else:
print("the slot has been taken")
player1_turn()

def ran():
position = random.choice(slots)
if board[position] == " ":
board.pop(position)
board.insert(position,player2_character)
print("the board has been updated")
board_game()
else:
ran()

#medium
def ai_turn_nor():
position = 10
stop = random.randint(1,2)
if stop == 1:
if board[0] == player1_character and board[1] == player1_character:
position = 2
elif board[1] == player1_character and board[2] == player1_character:
position = 0
elif board[0] == player1_character and board[2] == player1_character:
position = 1
elif board[3] == player1_character and board[4] == player1_character:
position = 5
elif board[4] == player1_character and board[5] == player1_character:
position = 3
elif board[3] == player1_character and board[5] == player1_character:
position = 4
elif board[6] == player1_character and board[7] == player1_character:
position = 8
elif board[7] == player1_character and board[8] == player1_character:
position = 6
elif board[6] == player1_character and board[8] == player1_character:
position = 7
elif board[0] == player1_character and board[4] == player1_character:
position = 8
elif board[4] == player1_character and board[8] == player1_character:
position = 0
elif board[0] == player1_character and board[8] == player1_character:
position = 4
elif board[2] == player1_character and board[4] == player1_character:
position = 6
elif board[4] == player1_character and board[6] == player1_character:
position = 2
elif board[2] == player1_character and board[6] == player1_character:
position = 4
elif board[0] == player1_character and board[3] == player1_character:
position = 6
elif board[3] == player1_character and board[6] == player1_character:
position = 0
elif board[0] == player1_character and board[6] == player1_character:
position = 3
elif board[1] == player1_character and board[4] == player1_character:
position = 7
elif board[4] == player1_character and board[7] == player1_character:
position = 1
elif board[1] == player1_character and board[7] == player1_character:
position = 4
elif board[2] == player1_character and board[5] == player1_character:
position = 8
elif board[5] == player1_character and board[8] == player1_character:
position = 2
elif board[2] == player1_character and board[8] == player1_character:
position = 5
else:
ai_turn_sim()
if position != 10:
if board[position] == " ":
board.pop(position)
board.insert(position,player2_character)
print("the board has been updated")
board_game()
else:
ran()
if stop == 2:
ai_turn_sim()

#hard
def ai_turn_hard():
position = 10
if board[0] == player2_character and board[1] == player2_character:
position = 2
elif board[1] == player2_character and board[2] == player2_character:
position = 0
elif board[0] == player2_character and board[2] == player2_character:
position = 1
elif board[3] == player2_character and board[4] == player2_character:
position = 5
elif board[4] == player2_character and board[5] == player2_character:
position = 3
elif board[3] == player2_character and board[5] == player2_character:
position = 4
elif board[6] == player2_character and board[7] == player2_character:
position = 8
elif board[7] == player2_character and board[8] == player2_character:
position = 6
elif board[6] == player2_character and board[8] == player2_character:
position = 7
elif board[0] == player2_character and board[4] == player2_character:
position = 8
elif board[4] == player2_character and board[8] == player2_character:
position = 0
elif board[0] == player2_character and board[8] == player2_character:
position = 4
elif board[2] == player2_character and board[4] == player2_character:
position = 6
elif board[4] == player2_character and board[6] == player2_character:
position = 2
elif board[2] == player2_character and board[6] == player2_character:
position = 4
elif board[0] == player2_character and board[3] == player2_character:
position = 6
elif board[3] == player2_character and board[6] == player2_character:
position = 0
elif board[0] == player2_character and board[6] == player2_character:
position = 3
elif board[1] == player2_character and board[4] == player2_character:
position = 7
elif board[4] == player2_character and board[7] == player2_character:
position = 1
elif board[1] == player2_character and board[7] == player2_character:
position = 4
elif board[2] == player2_character and board[5] == player2_character:
position = 8
elif board[5] == player2_character and board[8] == player2_character:
position = 2
elif board[2] == player2_character and board[8] == player2_character:
position = 5
else:
ai_turns_hard()

if position != 10:
if board[position] == " ":
board.pop(position)
board.insert(position,player2_character)
print("the board has been updated")
board_game()
else:
ai_turns_hard()

def ai_turns_hard():
position = 10
if board[0] == player1_character and board[1] == player1_character:
position = 2
elif board[1] == player1_character and board[2] == player1_character:
position = 0
elif board[0] == player1_character and board[2] == player1_character:
position = 1
elif board[3] == player1_character and board[4] == player1_character:
position = 5
elif board[4] == player1_character and board[5] == player1_character:
position = 3
elif board[3] == player1_character and board[5] == player1_character:
position = 4
elif board[6] == player1_character and board[7] == player1_character:
position = 8
elif board[7] == player1_character and board[8] == player1_character:
position = 6
elif board[6] == player1_character and board[8] == player1_character:
position = 7
elif board[0] == player1_character and board[4] == player1_character:
position = 8
elif board[4] == player1_character and board[8] == player1_character:
position = 0
elif board[0] == player1_character and board[8] == player1_character:
position = 4
elif board[2] == player1_character and board[4] == player1_character:
position = 6
elif board[4] == player1_character and board[6] == player1_character:
position = 2
elif board[2] == player1_character and board[6] == player1_character:
position = 4
elif board[0] == player1_character and board[3] == player1_character:
position = 6
elif board[3] == player1_character and board[6] == player1_character:
position = 0
elif board[0] == player1_character and board[6] == player1_character:
position = 3
elif board[1] == player1_character and board[4] == player1_character:
position = 7
elif board[4] == player1_character and board[7] == player1_character:
position = 1
elif board[1] == player1_character and board[7] == player1_character:
position = 4
elif board[2] == player1_character and board[5] == player1_character:
position = 8
elif board[5] == player1_character and board[8] == player1_character:
position = 2
elif board[2] == player1_character and board[8] == player1_character:
position = 5
else:
ran()

if position != 10:
if board[position] == " ":
board.pop(position)
board.insert(position,player2_character)
print("the board has been updated")
board_game()
else:
ran()

#making function that will check winner
def winnerCheck():
global game
global winner
global count
if (board[0] == "x" and board[1] == "x" and board[2] == "x"
or
board[3] == "x" and board[4] == "x" and board[5] == "x"
or
board[6] == "x" and board[7] == "x" and board[8] == "x"
or
board[0] == "x" and board[4] == "x" and board[8] == "x"
or
board[2] == "x" and board[4] == "x" and board[6] == "x"
or
board[0] == "x" and board[3] == "x" and board[6] == "x"
or
board[1] == "x" and board[4] == "x" and board[7] == "x"
or
board[2] == "x" and board[5] == "x" and board[8] == "x"):
if player1_character == "x":
print(f"\n{player_1} wins the match")
game = False
else:
print(f"\n{player_2} wins the match")
game = False
elif (board[0] == "o" and board[1] == "o" and board[2] == "o"
or
board[3] == "o" and board[4] == "o" and board[5] == "o"
or
board[6] == "o" and board[7] == "o" and board[8] == "o"
or
board[0] == "o" and board[4] == "o" and board[8] == "o"
or
board[2] == "o" and board[4] == "o" and board[6] == "o"
or
board[0] == "o" and board[3] == "o" and board[6] == "o"
or
board[1] == "o" and board[4] == "o" and board[7] == "o"
or
board[2] == "o" and board[5] == "o" and board[8] == "o"):
if player1_character == "o":
print(f"\n{player_1} wins the match")
game = False
else:
print(f"\n{player_2} wins the match")
game = False
else:
if count == 9:
print("tie")
game = False
return game

#main game

if mode.lower() == 'easy':
while game == True:
if whoWillGoFirst == 1:
player1_turn()
count = count + 1
winner_check = winnerCheck()
if winner_check == False:
break
ran()
count = count + 1
winner_check = winnerCheck()
if winner_check == False:
break
else:
ran()
count = count + 1
winner_check = winnerCheck()
if winner_check == False:
break
player1_turn()
count = count + 1
winner_check = winnerCheck()
if winner_check == False:
break

if mode.lower() == 'medium':
while game == True:
if whoWillGoFirst == 1:
player1_turn()
count = count + 1
winner_check = winnerCheck()
if winner_check == False:
break
ai_turn_nor()
count = count + 1
winner_check = winnerCheck()
if winner_check == False:
break
else:
ai_turn_nor()
count = count + 1
winner_check = winnerCheck()
if winner_check == False:
break
player1_turn()
count = count + 1
winner_check = winnerCheck()
if winner_check == False:
break

if mode.lower() == 'hard':
print(whoWillGoFirst)
while game == True:
if whoWillGoFirst == 1:
player1_turn()
count = count + 1
winner_check = winnerCheck()
if winner_check == False:
break
ai_turn_hard()
count = count + 1
winner_check = winnerCheck()
if winner_check == False:
break
else:
ai_turn_hard()
count = count + 1
winner_check = winnerCheck()
if winner_check == False:
break
player1_turn()
count = count + 1
winner_check = winnerCheck()
if winner_check == False:
break

# Web helper

## posted 4 months ago

webbrowser
if-else

This code will help you search in YouTube or google faster and easier. NOTE: THIS CODE ONLY WORKS ON PYTHON OR PYTHON IDE LIKE PYCHARM AND VISUAL STUDIO. YOU NEED TO ALSO INSTALL THE NEEDED PIP PACKAGES TO RUN THIS CODE. THE NEEDED COMMAND IS GIVEN ON THE CODE. please like my code toooo......

from googlesearch import * #pip install googlesearch

import pywhatkit #pip install pywhatkit

import webbrowser #pip install webbrowser

print("Hi I am Chithranjan in this code you can search in youtube or google faster and easier")

print("So what would you like to open google or youtube type in small letters")

print("What would you like to search in google")

query = input("WHat do you want me to search:")

chrome_path = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %s'

for url in search(query, tld="co.in", num=1, stop = 1, pause = 2):

song=input("What do you want to play in youtube")

print("Playing" +song)

pywhatkit.playonyt(song)

print("Thank you for using this code")

print('I would really appreciate if you like this code')

# Alarm Clock

## posted 6 months 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()