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".
import random
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()
Comments
Post a Comment