Showcase your coding talent
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.

Tekie.in

Bubble Sort

posted 8 days ago

utilities
mathematics
for loop

Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order.

'''

Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order.

Example: 

First Pass: 

( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1. 

( 1 5 4 2 8 ) –>  ( 1 4 5 2 8 ), Swap since 5 > 4 

( 1 4 5 2 8 ) –>  ( 1 4 2 5 8 ), Swap since 5 > 2 

( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5), algorithm does not swap them.

Second Pass: 

( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ) 

( 1 4 2 5 8 ) –> ( 1 2 4 5 8 ), Swap since 4 > 2 

( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) 

( 1 2 4 5 8 ) –>  ( 1 2 4 5 8 ) 

Now, the array is already sorted, but our algorithm does not know if it is completed. The algorithm needs one whole pass without any swap to know it is sorted.

Third Pass: 

( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) 

( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) 

( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) 

( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )

'''

#declaring a list and count variable

list_ = []

count = 0



#getting values in list

for i in range(1,int(input('how many no. are in the list : '))+1):

    num = int(input(f'num{i} = '))

    list_.append(num)

print(f'\nList = {list_}')



#main function starts here

for i in range(len(list_)-1):

    flag = 0

    for j in range(len(list_)-i-1):

        temp = 0

        count += 1

        if list_[j] > list_[j+1]:

            temp = list_[j+1]

            list_[j+1] = list_[j]

            list_[j] = temp

            flag = 1

    if flag == 0:

        break

        

print(f'Sorted List = {list_} \nTurns = {count}\n')

Tekie.in

Fun with friends

posted 8 days ago

games
if-else

This is a happy brithday test for whoever likes football. Remove the 3rd question. Change the persons name to be whoever your friend is or 'wierdo'.

let=("Dear Vandit,\nThis is Chaitan here. Happy 9th birthday. May you have the best day ever! I hope you like this quiz. You are one of the best football players I'v ever met. You have a lot of potentail in football. And once again, Happy Birthday!\nChaitan")
#question 1
messi='messi'
ronaldo='ronaldo'
right_count=0
count_neg=0
question=input('Who do you like more messi or ronaldo,chose one!')
if question==messi:
 right_count=right_count+1
 print('good choice.')
 print(right_count)
if question==ronaldo:
  count_neg=count_neg+1
  print('Nice choice!')
  print(count_neg)
 #question 2
captain='captain'
striker='striker'
question2=input('Would you rather be a captain of a football team or a striker of a football team?')
if question2==captain:
    right_count=right_count+1
    print(right_count)
    print('You will be a very good leader')
if question2==striker:
    count_neg=count_neg+1
    print('Good luck on your shots!')
    print(count_neg)
#question 3
question3=int(input('Which number are you in the Kc football team?'))
if question3==3 or 7 or 10 or 6:
    right_count=right_count+1
    print('Congragulations you passed the test and you are Vandit. Happy Birthday!')
    print(let)
else:
    count_neg=count_neg+1
    print('You failed the test and you are not Vandit!')

Tekie.in

Play Penalty Kicker Game

posted a month ago

games
function
for loop
elif

Welcome to Penalty Kicker. Game rules: First you will take penalties then the pc will(pc character name is James). Both sides will take 5 Penalties. You can choose three position in both taking Penalties and Goal Keeping, which are Middle, Left and Right. You have to type \'L\' for Left, \'M\' for Middle and \'R\' for Right. If you will type anything rather than L, M or R your chance will be taken as well as score will not increase. Best of Luck :-)

import random as rd

# declaring James positions
j_position = ['L', 'M', 'R']


# main game function
def game():
    # taking player name
    playerName = input('\nPlease enter your name : ')

    # declaring default scores
    jamesScore = 0
    playerScore = 0

    print('\nPenalty Time!\nBest of luck :-)')

    # penalty taking
    for i in range(5):
        # taking choice of james and player
        jamesChoice = rd.choice(j_position)
        playerChoice = input("\nType 'L' or 'l' for Left , 'M' or 'm' for Middle and 'R' or 'r' for Right : ")

        # comparing the choices
        # taking the case if james stopped the penalty
        if playerChoice.upper() in j_position:
            if playerChoice.upper() == jamesChoice:
                print('\nJames stopped the penalty!\n')
                # printing current scores
                print(f'Current Scores: \nPlayer Score = {playerScore} \nJames Score = {jamesScore} ')

            # if james didn't stopped then player scored
            else:
                print(f'\n{playerName} scored!\n')
                playerScore = playerScore + 1
                # printing current scores
                print(f'Current Scores: \nPlayer Score = {playerScore} \nJames Score = {jamesScore} ')

            # printing choices of james and player
            print(f'\nPlayer Chose = {playerChoice.upper()}\nJames Chose = {jamesChoice}')

        # if player didn't choose between L, M or R
        else:
            print('You can only choose L, M or R')

    print('\nPenalty Saving Time!\nStop James before he destroy you ;-)')

    # penalty saving
    for j in range(5):
        # taking choice of james and player
        jamesChoice = rd.choice(j_position)
        playerChoice = input("\nType 'L' or 'l' for Left , 'M' or 'm' for Middle and 'R' or 'r' for Right : ")

        # comparing the choices
        # taking the case if j stopped the penalty
        if playerChoice.upper() in j_position:
            if playerChoice.upper() == jamesChoice:
                print(f'\n{playerName} stopped the penalty!\n')
                # printing current scores
                print(f'Current Scores: \nPlayer Score = {playerScore} \nJames Score = {jamesScore} ')

            # if player didn't stopped then james scored
            else:
                print('\nJames scored!\n')
                jamesScore = jamesScore + 1
                # printing current scores
                print(f'Current Scores: \nPlayer Score = {playerScore}\nJames Score = {jamesScore} ')

            # printing choices of james and player
            print(f'\nPlayer Chose = {playerChoice.upper()}\nJames Chose = {jamesChoice}')

        # if player didn't choose between L, M or R
        else:
            print('You can only choose L, M or R')

    # DECLARING THE WINNER
    # if player won
    if playerScore > jamesScore:
        scoreDif = playerScore - jamesScore
        print(f'\n{playerName} won!\n')

        # a bit of commentry
        if scoreDif >= 3:
            print(f'{playerName} dominated James!')
        elif scoreDif == 1:
            print(f'That was a very close match but there can be only one winner and that is {playerName}')
        else:
            print('That was a wonderful match!')

    # if james won
    elif playerScore < jamesScore:
        scoreDif = jamesScore - playerScore
        print('\nJames won!\n')

        # a bit of commentry
        if scoreDif >= 3:
            print(f'James dominated {playerName}!')
        elif scoreDif == 1:
            print(f'That was a very close match but there can be only one winner and that is James')
        else:
            print('That was a wonderful match!')

    # if match tied
    else:
        print('The match is tied!\nWonderful play by both Players')

    # asking the player if he/she wanna play again
    again = input("Wanna play again? Press 'y'or 'Y' to play again or press 'x' or 'X' to exit : ")
    if again.lower() == 'y':
        game()
    else:
        print('\nThanks for playing. Hoping to see you soon')

    # explaining the game rules to players


print(
    'Welcome to Penalty Kicker!\n\nGame rules:\nFirst you will take penalties then the pc will(pc character name is James):\nBoth sides will take 5 Penalties\nYou can choose three position in both taking Penalties and Goal Keeping, That are Middle, Left and Right\nYou have to type \'L\' for Left, \'M\' for Middle and \'R\' for Right\nIf you will type anything rather than L, M or R your chance will be taken as well as score will not increase \nBest of Luck :-)\n')

# starting the game
start = input("Press 's'or 'S' to start game or press 'x' or 'X' to exit : ")

if start.lower() == 's':
    game()
else:
    print('Please come again :-)')

Tekie.in

Play Among Us

posted a month ago

games
while loop
elif

Among Us is a multiplayer game where players get dropped into an alien spaceship, sky headquarters or planet base, where each player is designated with a private role of either a “crewmate” and an “impostor.” This is an online multiplayer social deduction game, and a player can either be a crewmate or an imposter. One can play the game online or on local WiFi with their selected friends.

import random



print("Hello and welcome! This is Among Us for free!")



player1Name = input("Please enter the player 1 name: ")

player2Name = input("Please enter the player 2 name: ")

player3Name = input("Please enter the player 3 name: ")

player4Name = input("Please enter the player 4 name: ")



flag = 0

gameOver = -1

playersList = [player1Name, player2Name, player3Name, player4Name]

weapons = ["Machine Gun", "Rocket Launcher", "Dagger", "Alien Tentacles", "Acid", "Light saber", "Laser Ray"]

sabotageAreas = ["Electrical", "Command", "Navigation", "Engines", "Shields", "Security Cameras"]

adminPasswords = ["AmongUs@123", "ProPlayer@123", "Crewmate@123", "NonImposter@123", "SecurityAirlock@123"]



imposter = random.choice(playersList)

playersList.remove(imposter)



victim = random.choice(playersList)

weaponUsed = random.choice(weapons)

imposterSabotages = random.choice(sabotageAreas)

correctPass = random.choice(adminPasswords)

print(correctPass)



print(imposter)

while gameOver == -1:

    while flag == 0:

        action = input("Please enter what you want to do now, imposter: ")

        if action == "Kill":

            print(f"Ok, you killed " + victim + " by " + weaponUsed)

            flag = 1

            playersList.remove(victim)

            length = len(playersList)

            if length > 0:

                victim = random.choice(playersList)

                weaponUsed = random.choice(weapons)

            else:

                print("The Imposter wins")

                gameOver = 1

        elif action == "Report":

            print("You have reported an emergency meeting. Everyone, to the Cafeteria!")

            print(f"Whom do you vote to? {player1Name}, {player2Name}, {player3Name}, or {player4Name}?")

            vote = input("Please enter whom you want to vote: ")

            if vote == imposter:

                print(f"{vote} has been ejected, and he was the imposter. Crew mates win.")

                gameOver = 1

            else:

                "You have ejected a crew mate. Imposter remains."

                flag = 1

        elif action == "Sabotage":

            print("Ok, you have sabotaged the " + imposterSabotages + ". Now, complete the kills")

            flag = 1

            imposterSabotages = random.choice(sabotageAreas)

        elif action == "Enter Admin Room":

            userPass = input("Please enter password: ")

            if userPass == correctPass:

                print("You are cleared to go, crew mate!")

                correctPass = random.choice(adminPasswords)

                print(correctPass)

            else:

                print("Wrong Password. You are an Imposter!")

            flag = 1

        else:

            print("That is no action assigned to you, imposter!")

            flag = 1



    while flag == 1:

        action = input("Crew mate, please enter what you want to do now: ")

        tasks = ["Align Engines", "Destroy Asteroids", "Clear Airlock", "Swipe card in Admin Room", "Upload Navigation data"]

        taskDone = random.choice(tasks)

        if action == "Complete tasks":

            print("Ok, you have done the task '", taskDone, "'. Now complete other tasks and find the imposters!")

            taskDone = random.choice(tasks)

            flag = 0

        elif action == "Report":

            print("you have reported an emergency meeting. Everyone, to the Cafeteria!")

            print(f"Whom do you vote to? {player1Name}, {player2Name}, {player3Name}, or {player4Name}?")

            vote = input("Please enter whom you want to vote: ")

            if vote == imposter:

                print(f"{vote} has been ejected, and he was the imposter. Crew mates win.")

                break

            else:

                "You have ejected a crew mate. Imposter remains."

                flag = 0

        elif action == "Repair Sabotage Areas":

            print(f"Ok, you fixed {imposterSabotages}. Now, Find the imposter")

            imposterSabotages = random.choice(sabotageAreas)

            flag = 0

        else:

            print("That is no action assigned to you, crew mate!")

            flag = 0

Tekie.in

Hangman Game

posted a month ago

while loop
function
random
dictionary
if-else

Play the classic hangman game. Guess the correct word in the least number of tries and save the Hangman!

def get_player_name():
    player_name = input('Enter your name: ')
    return player_name
    
player_name = get_player_name()
print('Hello',player_name,',Lets Play Hangman!')

words_possible = {'secret':['_','_','c','_' ,'_','t'],'game':['_', '_', 'm', '_'],'dragon':['_','r','_','_','_','n'],'python':['_','_','t','_','o','_'],'interpreter':['_','_','_','e','_','p','_','_','t','_','r',]}
    
import random
word = random.choice(list(words_possible.keys()))
word_to_print = words_possible[word]
print(word_to_print)


chances=5
while chances>0:
    guess = input('Enter a character: ')
    
    if guess in word:
        print('Correct Guess')
        for i in range(len(word)):
            if word[i] == guess:
                word_to_print[i]=guess
        print(word_to_print)
        if '_' not in word_to_print:
            print('You Won!!')
            break
    else:
        chances = chances - 1 
        print('Wrong Guess')
        print('Chances left: ',chances)
   
    if chances == 0:
        print('Sorry you lost!!')
        print("   _____ \n"
            "  |     | \n"
            "  |     |\n"
            "  |     | \n"
            "  |     O \n"
            "  |    /|\ \n"
            "  |    / \ \n"
            "__|__\n")    
    elif chances == 1:
        
        print("  _____ \n"
          "  |     | \n"
          "  |     |\n"
          "  |     | \n"
          "  |     O \n"
          "  |     \n"
          "  |     \n"
          "__|__\n")
          
    elif chances == 2:
        
        print("  _____ \n"
          "  |     | \n"
          "  |     |\n"
          "  |     | \n"
          "  |      \n"
          "  |     \n"
          "  |     \n"
          "__|__\n")
          
    elif chances == 3:
        
        print("  _____ \n"
          "  |     | \n"
          "  |     |\n"
          "  |      \n"
          "  |      \n"
          "  |     \n"
          "  |     \n"
          "__|__\n")
          
    elif chances == 4:
        
        print("  _____ \n"
          "  |     | \n"
          "  |     \n"
          "  |      \n"
          "  |      \n"
          "  |     \n"
          "  |     \n"
          "__|__\n")

Tekie.in

Magic - Let's read your mind.

posted a month ago

if-else
elif
mathematics

You can think of a number between 1 to 60 and then the interpreter will guess your number. Hope you like it.

x=0

A=1

B=2

C=4

D=8

E=16

F=32



print("Welcome to Mind Reader Magic Trick!")



print("Think of a number from 1 to 60.")



print("\n1,5,3,7,9,11,13,15,17,19,39,33,31,37,35,53,57,59,51,55,47,41,45,49,43,25,23,27,21,29")

while True:

    print("Is the number in the list above?")

    in_list=input("Y for Yes and N for No: ")

    if in_list=="Y" or in_list=="y":

        x=x+A

        break

    elif in_list=="N" or in_list=="n":

        x=x

        break

    else:

        print("Invalid Input! Please try again.")

        

print("\n2,7,6,3,10,18,15,11,14,19,30,26,27,22,23,31,42,51,34,43,54,35,46,55,38,47,58,50,39,59")

while True:

    print("Is the number in the list above?")

    in_list=input("Y for Yes and N for No: ")

    if in_list=="Y" or in_list=="y":

        x=x+B

        break

    elif in_list=="N" or in_list=="n":

        x=x

        break

    else:

        print("Invalid Input! Please try again.")



print("\n4,6,7,5,12,20,15,14,13,21,30,28,23,29,22,38,36,31,37,39,47,46,52,44,45,55,54,60,53")



while True:

    print("Is the number in the list above?")

    in_list=input("Y for Yes and N for No: ")

    if in_list=="Y" or in_list=="y":

        x=x+C

        break

    elif in_list=="N" or in_list=="n":

        x=x

        break

    else:

        print("Invalid Input! Please try again.")



print("\n8,13,26,31,44,57,9,14,27,40,45,58,10,15,28,41,46,59,11,24,29,42,47,60,12,25,30,43,56")



while True:

    print("Is the number in the list above?")

    in_list=input("Y for Yes and N for No: ")

    if in_list=="Y" or in_list=="y":

        x=x+D

        break

    elif in_list=="N" or in_list=="n":

        x=x

        break

    else:

        print("Invalid Input! Please try again.")



print("\n16,22,57,49,25,17,23,27,54,60,18,24,48,59,30,19,26,53,29,56,20,31,58,50,51,21,52,28,55")



while True:

    print("Is the number in the list above?")

    in_list=input("Y for Yes and N for No: ")

    if in_list=="Y" or in_list=="y":

        x=x+E

        break

    elif in_list=="N" or in_list=="n":

        x=x

        break

    else:

        print("Invalid Input! Please try again.")



print("\n32,38,42,46,33,39,47,49,59,34,40,44,51,58,35,43,48,57,56,36,45,50,55,54,37,41,60,52,53")

while True:

    print("Is the number in the list above?")

    in_list=input("Y for Yes and N for No: ")

    if in_list=="Y" or in_list=="y":

        x=x+F

        break

    elif in_list=="N" or in_list=="n":

        x=x

        break

    else:

        print("Invalid Input! Please try again.")



print("Voilà!!! The number you thought was",x,".")

Tekie.in

Divisibility Tester

posted 2 months ago

utilities
elif

A program to test the divisibility of a number given provided by the user with any number in between 2 - 20.

print("""
Hello, and welcome to the Divisibility Tester ( 2 ) - ( 20 );

Type : 
               Test a number by  
  ( 2 )  - To |     ( 2 )
  ( 3 )  - To |     ( 3 )
  ( 4 )  - To |     ( 4 )
  ( 5 )  - To |     ( 5 )
  ( 6 )  - To |     ( 6 )
  ( 7 )  - To |     ( 7 )
  ( 8 )  - To |     ( 8 )
  ( 9 )  - To |     ( 9 )
  ( 10 )  - To |     ( 10 )
  ( 11 ) - To |     ( 11 )
  ( 12 ) - To |     ( 12 )
  ( 13 ) - To |     ( 13 )
  ( 14 ) - To |     ( 14 )
  ( 15 ) - To |     ( 15 )
  ( 16 ) - To |     ( 16 )
  ( 17 ) - To |     ( 17 )
  ( 18 ) - To |     ( 18 )
  ( 19 ) - To |     ( 19 )
  ( 20 ) - To |     ( 20 )
""")
test_num_choice = input(" \n")
check_num = int(input("Number you want to check : "))
print()

if test_num_choice == "2":
  if check_num % 2 == 0:
    print("\nThe number you have entered is divisible by ( 2 )\n")
  elif check_num % 2 != 0:
    print("\nThe number you have entered is not divisible by ( 2 )\n")

if test_num_choice == "3":
  if check_num % 3 == 0:
    print("\nThe number you have entered is divisible by ( 3 )\n")
  elif check_num % 3 != 0:
    print("\nThe number you have entered is not divisible by ( 3 )\n")

if test_num_choice == "4":
  if check_num % 4 == 0:
    print("\nThe number you have entered is divisible by ( 4 )\n")
  elif check_num % 4 != 0:
    print("\nThe number you have entered is not divisible by ( 4 )\n")

if test_num_choice == "5":
  if check_num % 5 == 0:
    print("\nThe number you have entered is divisible by ( 5 )\n")
  elif check_num % 5 != 0:
    print("\nThe number you have entered is not divisible by ( 5 )\n")

if test_num_choice == "6":
  if check_num % 6 == 0:
    print("\nThe number you have entered is divisible by ( 6 )\n")
  elif check_num % 6 != 0:
    print("\nThe number you have entered is not divisible by ( 6 )\n")

if test_num_choice == "7":
  if check_num % 7 == 0:
    print("\nThe number you have entered is divisible by ( 7 )\n")
  elif check_num % 7 != 0:
    print("\nThe number you have entered is not divisible by ( 7 )\n")

if test_num_choice == "8":
  if check_num % 8 == 0:
    print("\nThe number you have entered is divisible by ( 8 )\n")
  elif check_num % 8 != 0:
    print("\nThe number you have entered is not divisible by ( 8 )\n")

if test_num_choice == "9":
  if check_num % 9 == 0:
    print("\nThe number you have entered is divisible by ( 9 )\n")
  elif check_num % 9 != 0:
    print("\nThe number you have entered is not divisible by ( 9 )\n")

if test_num_choice == "10":
  if check_num % 10 == 0:
    print("\nThe number you have entered is divisible by ( 10 )\n")
  elif check_num % 10 != 0:
    print("\nThe number you have entered is not divisible by ( 10 )\n")

if test_num_choice == "11":
  if check_num % 11 == 0:
    print("\nThe number you have entered is divisible by ( 11 )\n")
  elif check_num % 11 != 0:
    print("\nThe number you have entered is not divisible by ( 11 )\n")

if test_num_choice == "12":
  if check_num % 12 == 0:
    print("\nThe number you have entered is divisible by ( 12 )\n")
  elif check_num % 12 != 0:
    print("\nThe number you have entered is not divisible by ( 12 )\n")

if test_num_choice == "13":
  if check_num % 13 == 0:
    print("\nThe number you have entered is divisible by ( 13 )\n")
  elif check_num % 13 != 0:
    print("\nThe number you have entered is not divisible by ( 13 )\n")

if test_num_choice == "14":
  if check_num % 14 == 0:
    print("\nThe number you have entered is divisible by ( 14 )\n")
  elif check_num % 14 != 0:
    print("\nThe number you have entered is not divisible by ( 14 )\n")

if test_num_choice == "15":
  if check_num % 15 == 0:
    print("\nThe number you have entered is divisible by ( 15 )\n")
  elif check_num % 15 != 0:
    print("\nThe number you have entered is not divisible by ( 15 )\n")

if test_num_choice == "16":
  if check_num % 16 == 0:
    print("\nThe number you have entered is divisible by ( 16 )\n")
  elif check_num % 16 != 0:
    print("\nThe number you have entered is not divisible by ( 16 )\n")

if test_num_choice == "17":
  if check_num % 17 == 0:
    print("\nThe number you have entered is divisible by ( 17 )\n")
  elif check_num % 17 != 0:
    print("\nThe number you have entered is not divisible by ( 17 )\n")

if test_num_choice == "18":
  if check_num % 18 == 0:
    print("\nThe number you have entered is divisible by ( 18 )\n")
  elif check_num % 18 != 0:
    print("\nThe number you have entered is not divisible by ( 18 )\n")

if test_num_choice == "19":
  if check_num % 19 == 0:
    print("\nThe number you have entered is divisible by ( 19 )\n")
  elif check_num % 19 != 0:
    print("\nThe number you have entered is not divisible by ( 19 )\n")

if test_num_choice == "20":
  if check_num % 20 == 0:
    print("\nThe number you have entered is divisible by ( 20 )\n")
  elif check_num % 20 != 0:
    print("\nThe number you have entered is not divisible by ( 20 )\n")

Tekie.in

Temperature Converter

posted 2 months ago

utilities
elif

A small program to convert the temperature between Celsius, Farenheit & Kelvin.

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

Tekie.in

Guess the word game in python

posted 2 months ago

games
for loop
if-else

Guess the later in the word. If the guessed letter is correct you will be allowed to continue to guess till you find the right word else you loose.

# Creating the right word which the player will guess.
right_word = "banana"

# Creating the guess word.
guess_word = "_" * len(right_word)

# Calculating the number of chances.
chance = len(right_word) // 2

# Game start message
print(f"You get {chance} chances to guess this word " + "_ " * len(right_word) + "\n")

# Starting the guessing game.
for i in range(chance):
    
  # Taking input from the user.
  guess = input(f"Guess Number : {i + 1}\nEnter your guess : ")
    
  # If the guess word is the right word.
  if guess == right_word:
        
    # Display the winning message
    print("You Won! 🎉 \t Yipeeeee..")
    break
    
  # Now checking whether the letter is there in right word.
  if right_word.find(guess) != -1:
        
    # Placing the guess word.
    for j in range(len(right_word)):
      if right_word[j] == guess:
        guess_word = guess_word[:j] + guess + guess_word[j + 1:]
    print("Guessed Word: " + guess_word + "\n")
        
    # Check guess word is right or not.
    if guess_word == right_word:
      # Display the winning message
      print("You Won! 🎉 \tYipeeeee..")
      break
  else:
    print("Wrong Guess 😭  \tTry again!" + "\n")
  if i == chance - 1:
    print("GAME  OVER!!!")

Tekie.in

Date & Time in a structured format

posted 2 months ago

utilities
elif

A small program to display date or time or both in a structured format.

# Importing
import datetime

# Formatting
time = str(datetime.datetime.now())
time = time[:19]
date = time[:10]
date = date.replace("-", " | ")
time = time[10:]
time = time.replace(":", " | ")

# Taking the user's choice
choice = input("""Type
"1" - For Date Only
"2" - For Time Only
"3" - For Both\n""")

# Choosing
if choice == "1":
  print("\n", " " * 6 + "| YYYY |" + " " + "MM" + " | " + "DD |")
  print("Date : " + "| " + date + " |", "\n")

elif choice == "2":
  print("\n", " " * 6 + "| HH |" + " " + "MM" + " | " + "SS |")
  print("Time : " + "|" + time + " |", "\n")

elif choice == "3":
  print("\n", " " * 6 + "| YYYY |" + " " + "MM" + " | " + "DD |")
  print("Date : " + "| " + date + " |")
  print("\n", " " * 6 + "| HH |" + " " + "MM" + " | " + "SS |")
  print("Time : " + "|" + time + " |", "\n")

elif choice != "1" and choice != "2" and choice != "3":
  print("Invalid Input!")