Question

Can someone write a simple memory game program in python

Can someone write a simple memory game program in python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

uick Launch (Ci+a Microsot Viaa visual Studi Fie Feit w Pmjert Build Dehug Team Toele Tet Anaye Windew Help #Packages for cle-----------------------------------------

Program

#Packages for clear screen, sleep and random generation
import os
import time
import random
#Method to shows steps in the game print at start
def gameRule():
    print("          WELCOME TO SIMPLE MEMORY GAME")
    print("Rules\n------")
    print("1. Look at the console you can see some words in 1 seconds.Try to memorise")
    print("2. Prompt for the specified position word guess");
    print("3. If same print win message , otherwise lose message")
    print("4. Do you want to guess again")
    print("5. If yes start from step1 again\n")
#Main method
def main():
    gameRule()
    time.sleep(2)
    # Read word randomly from the file
    myWords = open('C:/Users/deept/Desktop/w.txt').read().splitlines()
    ch='Y'
    #Loop until no
    while(ch=='Y'):
        #Print words
        print("Memorizing words:\n",myWords)
        #Keep that 1 seconds
        time.sleep(1)
        #Clear screen
        os.system('cls')
        #Generate a position
        n=random.randint(0,len(myWords)-1)
        #Prompt for guess
        inpString='Enter the '+str(n+1)+' position element in the list: '
        guess=input(inpString)
        #If same then win message
        if(guess==myWords[n]):
            print ("Hurrai !!!!!!, you win")
        #Otherwise loss message
        else:
            print ("Better luck next time , you lose")
        #Repeatation part
        ch=input('Do you want to continue(y/n): ')
        ch=ch.upper()
        #Error check
        while(ch!='Y' and ch!='N'):
            print("ERROR!!!You should enter y/n.")
            ch=input('Do you want to continue(y/n): ')
            ch=ch.upper()
        os.system('cls')
    print(' Good Bye!!!')
#Starts here
main()

---------------------------------

          WELCOME TO SIMPLE MEMORY GAME
Rules
------
1. Look at the console you can see some words in 1 seconds.Try to memorise
2. Prompt for the specified position word guess
3. If same print win message , otherwise lose message
4. Do you want to guess again
5. If yes start from step1 again

Enter the 4 position element in the list: Gippy
Hurrai !!!!!!, you win
Do you want to continue(y/n):

Add a comment
Know the answer?
Add Answer to:
Can someone write a simple memory game program in python
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT