Python Tutorial, Play Jumble Word

Game: Jumble word

In this program, I will show you how the jumble word known by the computer. And how you program it.

Now in this program

Two player: Every time the turn will change, and the computer will give jumble value to player and ask some question that what is in your mind? if you give right jumble word then score is increased by one. Similarly with player two.

Code :


import random

def choose():
    words = ["rainbow","computer","science","program","player","reverse","water"]
    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)
    
    
def play():
    p1name=input("Player1, Please enter your name=")
    p2name=input("Player2, Please enter your name=")
    pp1 = 0
    pp2 = 0
    turn = 0
    while(1):
        #computer
        picked_word = choose()
        #create question
        qn = jumble(picked_word)
        print(qn)
        if turn%2==0:
            print(p1name, "Your turn.")
            ans=input("What is on my mind?")
            if ans == picked_word:
                pp1=pp1+1
                print("your score is : " ,pp1)
            else:
                print("Better luck next time. I thought: ",picked_word)
                c= input("Press 1 to continue and 0 to quit : ")
                if c== 0:
                    thank(p1name,p2name,pp1,pp2)
                    break
                #player2
        else:
            print(p2name,"your turn. ")
            if ans == picked_word:
                pp2=pp2+1
                print("your score is : " ,pp2)
            else:
                print("Better luck next time. I thought: ",picked_word)
                c= input("Press 1 to continue and 0 to quit : ")
                if c== 0:
                    thank(p1name,p2name,pp1,pp2)
                    break
        turn = turn+1
play()


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top