Skip to main content

GAME : SOLVE JUMBLED WORDS! ( Game Programming With Python)

 Hello there, in this article we are going to help the python learning beginners to create a simple game called as "SOLVE THE JUMBLED WORDS". 




The piece of code for the same is given :

import random

 def choose():

    words=['rainbow','computer','science','programming','Cool','mathematics','Good','player','condition','student','happy','hope','Joker','Simple','deaf']

    pick=random.choice(words)

    return pick

 

def jumble(word):

    jumbled="".join(random.sample(word,len(word)))

    return jumbled

 

def thank(p1n,p2n,p1,p2):

    print(p1n,"Your score is : ",p1)

    print(p2n,"Your score is : ",p2)

    print("Thanks for playing")

    print("Have a nice day!")

 

   

def play():

    p1name=input("Enter the name of player 1: ")

    p2name=input("Enter the name of player 2: ")

    pp1=0

    pp2=0

    turn=0

    while(1):

        #computer's task

        picked_word=choose()

        qn=jumble(picked_word)

        print(qn)

        #player1

        if turn%2==0:

            print("Its your turn: ",p1name)

            ans=input("Whats on your mind: ")

            if ans==picked_word:

                pp1=pp1+1

                print("Congratulations! Your current score is: ",pp1)

            else:

                print("Better Luck next time! The correct word was : ",picked_word)

            c=input("Press 1 to continue or 0 to stop.")

            c=int(c)

            if c==0:

                thank(p1name,p2name,pp1,pp2)

                break

            #player

        else:

            print("Its your turn: ",p2name)

            ans=input("Whats on your mind: ")

            if ans==picked_word:

                pp2=pp2+1

                print("Congratulations! Your current score is: ",pp2)

            else:

                print("Better Luck next time! The correct word was : ",picked_word)

            c=input("Press 1 to continue or 0 to stop.")

            c=int(c)

            if c==0:

                thank(p1name,p2name,pp1,pp2)

                break

        turn=turn+1

play()

 Let's see the output of this code.


output,python code, gaming, python, programming


Stay tuned for more such projects.

You can mail or comment below for any doubt regarding the above code.



Comments

Popular posts from this blog

Know the current Covid status of your country using Python!

 We all are aware about COVID-19, i.e. coronavirus infectious disease 2019.  Isn't it fascinating, using python for numerous purpose! So, here is the python program that can help you know the status of COVID-19 of your country. -------------------------------------------------------------------------------------------------------------------------- For this you need to install one package using the pip command. pip install covid -------------------------------------------------------------------------------------------------------------------------- from covid import Covid covid=Covid() cases=covid.get_status_by_country_name("India") #enter the name of the country you want to know the status for x in cases:     print(x,":",cases[x]) -------------------------------------------------------------------------------------------------------------------------- Output of the above program, giving current status is: id : 80 country : India confirmed : 9857029 active : 35...

Drawing a star with stamp of turtle in python!

  Here is the code for the same: import   turtle star = turtle . Turtle () star. color ( "pink" ) star. shape ( "turtle" ) wn = turtle . Screen () wn. bgcolor ( "black" ) for  i  in   range ( 100 ):     star. forward ( 200 + 20 * i)     star. stamp ()     star. right ( 144 ) turtle . speed ( 9 ) turtle .done() Output of the above code: 

Snakes and Ladders Game!

 Hey! Welcome back to my blog!  In this blog we will learn to create our one of the favorite childhood game "SNAKES AND LADDERS". I hope everyone is aware about this game. I still remember I used to play this game during my summer vacation and perhaps those were the best days.  Okay, let's start python coding for the same game! So for this particular piece of code, I have assumed the following game board and according to that numbers are assigned to the snakes and ladders. --------------------------------------------------------------------------------------------------------------- from PIL import Image import random end=100 def show_board():     img=Image.open('C:\\Users\\asus01\\Desktop\\slb.jpg')     img.show() def check_ladder(points):         if points==3:             print("Ladder")             return 51         elif points==6:     ...