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

What is turtle.stamp() in python?

turtle.stamp() turtle.stamp() is used to stamp a copy of the turtle shape, it prints the shape at that point and moves forward with the instructions. Here shape of the turtle does not matter. It does the same for every turtle shape.  Example:  Here is the example of stamp() used: import   turtle def   tri ():      for   i   in   range ( 10 ):          turtle . degrees ( 60 )          turtle . forward ( 200 + 10 * i )          turtle . stamp ()          turtle . right ( 200 ) turtle . speed ( 7 ) turtle . color ( "orange" )         tri () turtle . done () For more such posts, stay tuned!

Introduction to Artificial Intelligence

WHAT  IS  ARTIFICIAL  INTELLIGENCE? Artificial Intelligence                  Concept of AI goes back to the classical ages. Under greek   mythology , the concept of machines and mechanical men were well thought off. In 1950, “ALAS TURING”, published landmark paper “Computing Machinery and Intelligence”, proposes “Imitation Game”, known as the famous “TURING TEST” He speculated about the possibility of creating machines that think. Unfortunately, until this date we haven’t found a machine that has fully cleared the Turin Test. Followed by this was the era of 1951, in which MARVIN MINSKY and DEAN EDMUNDS built the first   artificial neural network using 3000 vacuum tubes stimulating 40 neurons. Next in 1952,   ARTHUR SAMUEL, wrote the first machine learning program(Game AI) for checkers. In 1956, there was the birth of AI. JOHN Mc CARTHY, first coined the term “AI” at the Dartmouth Conference. Coming to 1959, first AI laboratory, where   the research on AI has begu

Use Python to know about Artificial Intelligence

 Hey, welcome back!   You'll be happy to know that you can use python to know about any topic related to your research from wikipedia. Let's check the code.     #import module import requests import pandas as pd from bs4 import BeautifulSoup def getdata(url):     r=requests.get(url)     return r.text htmldata=getdata("https://en.wikipedia.org/wiki/Artificial_Intelligence") soup= BeautifulSoup(htmldata, 'html.parser') data='' for data in soup.find_all("p"):     print(data.get_text()) Here is the output of the code. You can use the same code for acquiring various kind of information just by doing a slight change.  htmldata=getdata("https://en.wikipedia.org/wiki/(#Entering the topic name") Assume, you want to know about solar eclipse, here is the code for it. Observe the slight change in it. #import module import requests import pandas as pd from bs4 import BeautifulSoup def getdata(url):     r=requests.get(url)     return r.text htmld