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

Magic - Let's read your mind.

posted a year 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

Break the Code

posted 6 months 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")
ready=input("keep your code ready and type small 'y' and press enter when you are ready ")
print("Try guessing mine first")

print("-------------------------Round 1-------------------------")
try1 = input("Type your guess")
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❀πŸ”₯πŸŽ‰")

Tekie.in

Play Penalty Kicker Game

posted a year 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

Tic Tac Toe or 'X' and 'O'

posted a year ago

if-else
function
while loop
games

Tic-tac-toe, is a paper-and-pencil game for two players, X or x and O or o, who take turns marking the spaces in a 3Γ—3 grid. The player who succeeds in placing three of their marks in a diagonal, horizontal, or vertical row is the winner. It is a solved game with a forced draw assuming best play from both players.

import random



player_1 = input("Enter player 1 name : ")

player_2 = input("Enter player 2 name : ")

characterChoose = random.randint(1,2)

game = True

winner = "none"

count = 0



#assign characters "x or o"

if characterChoose == 1:

    print(f"{player_1} will choose first")

    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"

else:

    print(f"{player_2} will choose first")

    player2_character = input(f"{player_2} what character do you want : (x or o)")

    if player2_character == "x":

        player1_character = "o"

    else:

        player1_character = "x"

        player2_character = "o"

print(f"{player_1} = {player1_character}\n{player_2} = {player2_character}\n")



#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 player2_turn():

    position = int(input(f"{player_2} which position do you want to place your character (1 to 9)"))

    position = position - 1

    if board[position] == " ":

        board.pop(position)

        board.insert(position,player2_character)

        print("the board has been updated")

        board_game()

    else:

        print("the slot has been taken")

        player2_turn()

        

#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

while game == True:

    if whoWillGoFirst == 1:

        player1_turn()

        count = count + 1

        winner_check = winnerCheck()

        if winner_check == False:

            break

        player2_turn()

        count = count + 1

        winner_check = winnerCheck()

        if winner_check == False:

            break

    else:

        player2_turn()

        count = count + 1

        winner_check = winnerCheck()

        if winner_check == False:

            break

        player1_turn()

        count = count + 1

        winner_check = winnerCheck()

        if winner_check == False:

            break

Tekie.in

Hypo-Leg-Sqrt

posted 9 months ago

mathematics
if-else

This is a code by KDBeditz_OfficialΒ© and Chitranjan Now you can find hypotenuse, Leg and square root of any number

choice = input("Enter 1 for hypotenuse, enter 2 for length of the leg and 3 for square root. ENTER YOUR CHOICE : ")
if choice == '1':
    num1=int(input("Enter value of leg1 : "))
    num2=int(input("Enter value of leg2 : "))
    a = num1*num1
    b = num2*num2
    numa = a+b
    num_sqrt = numa ** 0.5
    print("The hypotenuse is", num_sqrt)

 
if choice == '2':
    print("NOTE πŸ›‘ The length of hypotenuse is always greater than the leg")
    num3=int(input("Enter value of leg: "))
    num4=int(input("Enter value of hypotenuse: "))
    c = num3*num3
    d = num4*num4
    numb = d-c
    num_sqrt = numb ** 0.5
    print("the length of the other leg is",num_sqrt)
    
    
       
if choice == '3':
    num = float(input('Enter a number: '))
    num_sqrt = num ** 0.5
    print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))

Tekie.in

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

choice = input("Youtube or google")

if choice == 'google':

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

                webbrowser.open("https://google.com/search?q=%s" % query)

        print("opening google")





if choice == 'youtube':

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

Tekie.in

Jairaj Spacex

posted 8 months ago

if-else

Know your cost of traveling to planets like mars and venus with Jairaj Spacex

print("Welcome to Jairaj Spacex!\n")
name=input(("Enter the persons name who want to go on space: "))
print("\nWelcome",name,"to Jairaj Spacex organization.\n")
rocket=input(("Tell the name of rocket through which you want to enter space. \nWe have two types of rockets \n1. fuel x \n2. fuel y \n"))
if rocket == "fuel x":
  print("Okay",name,"you will be traveling using",rocket,".\n")
  print("Where do you want to travel in space?")
  planet=input("You can travel to \n1. moon \n2. mars \n3. mercury \n4. venus \n5. jupiter \n")
  if planet == "moon":
      print("you have to travel this 12,000,000 km")
      fuel_x_cost=12343
      price=12000000*fuel_x_cost
      print("You have to pay the cost: ",price) 
  if planet == "mercury":
      print("you have to travel this 212,000,000 km")
      fuel_x_cost=12343
      price=212000000*fuel_x_cost
      print("You have to pay the cost: ",price)
  if planet == "venus":
      print("you have to travel this 22,000,000 km")
      fuel_x_cost=12343
      price=22000000*fuel_x_cost
      print("You have to pay the cost: ",price)
  if planet == "mars":
      print("you have to travel this 2122,000,000 km")
      fuel_x_cost=12343
      price=2122000000*fuel_x_cost
      print("You have to pay the cost: ",price)
  if planet == "jupiter":
      print("you have to travel this 21222,000,000 km")
      fuel_x_cost=12343
      price=21222000000*fuel_x_cost
      print("You have to pay the cost: ",price)
elif rocket == "fuel y":
    print("Okay",name,"you will be traveling using",rocket,".\n")
    print("Where you want to travel in space?")
    planet=input(("You can travel to \n1. moon \n2. mars \n3. mercury \n4. venus \n5. jupiter \n"))
    if planet == "moon":
      print("you have to travel this 12,000,000 km")
      fuel_y_cost=1234
      price=12000000*fuel_y_cost
      print("You have to pay the cost: ",price) 
    if planet == "mercury":
      print("you have to travel this 212,000,000 km")
      fuel_y_cost=1234
      price=212000000*fuel_y_cost
      print("You have to pay the cost: ",price)
    if planet == "venus":
      print("you have to travel this 22,000,000 km")
      fuel_y_cost=1234
      price=22000000*fuel_y_cost
      print("You have to pay the cost: ",price)
    if planet == "mars":
      print("you have to travel this 2122,000,000 km")
      fuel_y_cost=1234
      price=2122000000*fuel_y_cost
      print("You have to pay the cost: ",price)
    if planet == "jupiter":
      print("you have to travel this 21222,000,000 km")
      fuel_y_cost=1234
      price=21222000000*fuel_y_cost
      print("You have to pay the cost: ",price)

else:
    print("Something went wrong!")

Tekie.in

Snakes And Ladders

posted 8 months ago

games
function
elif

100 squares full of traps and tricks…Roll the dice and try your luck! Ladders will take you up but Snakes will take you down!

import random

Max = 100
player1squarenumber = 0 
player2squarenumber = 0

print("""Welcome to Snake and Ladder Game.


    Rules:
      1. Initally both the players are at starting position i.e. 0. 
         Take it in turns to roll the dice. 
         Move forward the number of spaces shown on the dice.
      2. If you lands at the bottom of a ladder, you can move up to the top of the ladder.
      3. If you lands on the head of a snake, you must slide down to the bottom of the snake.
      4. The first player to get to the FINAL position is the winner.
      5. Type R to roll the dice
      6. Type Q to quit.
      7. Have fun!""")
      
player_turn_text = [
    "Your turn.",
    "Go.",
    "Please proceed.",
    "Lets win this.",
    "Are you ready?",
    "",
]
      
snakeBite = [
    "woops",
    "ow",
    "snake bite",
    "oh no",
    "sorry"
]

ladder_jump = [
    "woohoo",
    "woww",
    "nailed it",
    "oh good ...",
    "yaayyy"
]

snakes = {
    8: 5,
    18: 1,
    26: 8,
    39: 7,
    51: 2,
    54: 23,
    56: 1,
    60: 20,
    75: 30,
    83: 40,
    85: 59,
    90: 48,
    92: 25,
    97: 87,
    99: 5
}

ladders = {
    2: 20,
    6: 19,
    11: 28,
    15: 39,
    17: 78,
    22: 37,
    38: 50,
    49: 61,
    57: 77,
    61: 76,
    73: 87,
    81: 97,
    88: 98
}

print("\n")
print("\n")
        
def getDiceValue():
    dicevalue = random.randint(1, 6)
    print("It is a " + str(dicevalue))
    return dicevalue
        
def GotSnakeBite(old_value, current_value, player_name):
    print("\n" + random.choice(snakeBite).upper() + " ~~~~~~~~>")
    print("\n" + player_name + " you got a snake bite. You are down from " + str(old_value) + " to " + str(current_value))


def LadderJump(old_value, current_value, player_name):
    print("\n" + random.choice(ladder_jump).upper() + " ########")
    print("\n" + player_name + " you climbed the ladder from " + str(old_value) + " to " + str(current_value))   
    
def GameStart():
    player1squarenumber = 0 
    player2squarenumber = 0 
    
    player1name = input("Please enter a name for first player: ")
    player2name = input("Please enter a name for second player: ")
    print("\n")
    print("Game will be played between '" + player1name + "' and '" + player2name + "'.")
    print("\n")
    
    while True:
        input1 = input(player1name + ": " + random.choice(player_turn_text) + " Press R to roll the dice: ")
        if input1 == "Q":
            break
        print("Rolling dice...")
        diceValue = getDiceValue()
        if player1squarenumber + diceValue > Max:
            print("You need " + str(Max - player1squarenumber) + " to win.")
        else:
            player1squarenumber = player1squarenumber + diceValue
            
        if player1squarenumber == Max:
            print("Congratulations! " + player1name + " won the game.")
            print("\n")
            break
        elif player1squarenumber in ladders:
            old_value = player1squarenumber
            player1squarenumber = ladders[player1squarenumber]
            LadderJump(old_value, player1squarenumber, player1name)
            
        elif player1squarenumber in snakes:
            old_value = player1squarenumber
            player1squarenumber = snakes[player1squarenumber]
            GotSnakeBite(old_value, player1squarenumber, player1name)
            
        print(player1name + " current number: " + str(player1squarenumber))
        print("\n")
            
        input2 = input(player2name + ": " + random.choice(player_turn_text) + " Press R to roll the dice: ")
        if input2 == "Q":
            break
        print("Rolling dice...")
        diceValue = getDiceValue()
        
        if player2squarenumber + diceValue > Max:
            print("You need " + str(Max - player2squarenumber) + " to win.")
        else:
            player2squarenumber = player2squarenumber + diceValue
            
        if player2squarenumber == Max:
            print("Congratulations! " + player2name + " won the game.")
            break
        elif player2squarenumber in ladders:
            old_value = player2squarenumber
            player2squarenumber = ladders[player2squarenumber]
            LadderJump(old_value, player2squarenumber, player2name)
            
        elif player2squarenumber in snakes:
            old_value = player2squarenumber
            player2squarenumber = snakes[player2squarenumber]
            GotSnakeBite(old_value, player2squarenumber, player2name)
            
        print(player2name + " current number: " + str(player2squarenumber))
        print("\n")
            
GameStart()

Tekie.in

Bubble Sort

posted 10 months 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

Zombie Attack

posted a year ago

games
random
elif
while loop

In this game you have to kill zombies. How to play: 1. There can be ZOMBIE ANYWHERE you have to WRITE a direction(Up, Down, Right, Left, Front, Back). 2. Zombie will be on random direction EACH TIME, if you write the direction where the zombie is: 25πŸ’– will be Added to your life. 3. Or else: 10πŸ’˜ will be Subtracted from your life. 4. Your default life is: 200. 5. You have 3 Skips too. 6. If your life will be 0: The game will will END and you will get your score. BE READY!

import random as r

print(' ')

print("""Welcome to Zombie Attack!

How to play:

1. There can be zombie on any direction(Up,Down,Left,Right,Front,Back)! You have to write a direction.

2. If you write the direction where the zombie is: 25πŸ’– will be added to your life.

3. Or else: 10πŸ’˜ will be subtracted from your life.

4. Your default life is: 200

5. When your life gets to 0: You will get your score, your highest life, and the game will end!

Be reday!""")

print(' ')

Start = input("Write 'S' or else it won't start: ")

print(' ')

if Start != 'S':

    print('Closing Game...')

    print(' ')

else:

    score = 0

    life = 200

    times = 1

    skips_left = 4

    AICheatCode_left = 3

    highest_life = life

    while True:

        Direction = input(f'''Enter a direction(U for up, D for down, R for right, L for left, F for front, B for back)

or write 'Stop', 'Skip'(You have only {skips_left} skips_left): ''')

        if Direction != 'AICheatCode':

            Direction = Direction.lower()

        print(' ')

        Zombie_Direction = r.choice(['u','d','f','r','l','b'])

        if life <= 0:

            print(f'''Your life is: {life}

Your score is: {score}

Your survived: {times} times

You had: {skips_left} skips left

Your highest life was: {highest_life}''')

            exit()

        if Direction == 'stop':

            print(f'''Your life is: {life}

Your score is: {score}

Your survived: {times} times

You had: {skips_left} skips left

Your highest life was: {highest_life}''')

            print('')

            break

        elif Direction == 'skip':

            if skips_left != 0:

                score = score+0.25

                skips_left = skips_left-1

                times = times+1

                print(f'''Your life is: {life}

Your score is: {score}

Your survived: {times} times

You have: {skips_left} skips left

By the way, there was a zombie on {Zombie_Direction}''')

                print(' ')

                continue

            else:

                print('You cant skip as you have 0 skips!')

                print(' ')

                continue

        else:

            if Direction == 'AICheatCode':

                if AICheatCode_left != 0:

                    score = score+2

                    times = times+2

                    life = life+25

                    AICheatCode_left = AICheatCode_left-1

                    print(f'You have {AICheatCode_left} AICheatCodes left')

                    print(' ')

                else:

                    print('You have 0 AICheatCodess left')

                    print(' ')

            elif Direction == Zombie_Direction:

                score = score+1

                times = times+1

                life = life+25

                print(f'''Your life is: {life}

Your score is: {score}

Your survived: {times} times

You have: {skips_left} skips left

You killed the zombie on {Zombie_Direction}!''')

                print(' ')

            else:

                times = times+1

                life = life-10

                print(f'''Your life is: {life}

Your score is: {score}

Your survived: {times} times

You have: {skips_left} skips left

By the way, there was a zombie on {Zombie_Direction}!''')

                print(' ')

        if highest_life < life:

            highest_life = life