Hi there, I've been trying to create a memory test game, but been trying to figure out a way to get the output to display for a limited amount of time, any suggestions geeks in the house.

Recommended Answers

All 6 Replies

time.sleep

commented: thanks all the same +3

i know about the time module, but how do i use it with the print statement. examples please...

Here anyway console based code even more clever is to use tkinter or other GUI and show/hide label.

from __future__ import print_function
from random import choice
import time
import sys

try:
    input = raw_input
except:
    pass

TIMEOUT = 0.4

things = 'kittens', 'puppies', 'stars'
response, this,  tried, total = '', '', set(), 0


while len(tried) < len(things):
    while not this or this in tried:
        this = choice(things)
    tried.add(this)
    print(this, end='')
    time.sleep(TIMEOUT)
    sys.stdout.write('\r')
    sys.stdout.flush()
    response = input('Write the word:')
    if response == 'q':
        break
    correct = response == this
    total += correct
    print('You got it!' if correct else 'No, you did not get it correct')

if len(tried) == len(things):
    print('You tried all words, and got right %i/%i' % (total, len(tried)))

Very inventive of you tonyjv. Here's my simplistic attempt :).

from time import sleep
import os

def lotsofprints():
    print "\n" * 40
    
message = "read me soon because I'm bound to disappear"

print message
sleep(1) # or .xx for milliseconds
#os.system("cls") #uncomment if running on windows from a command line
lotsofprints() #for use in idle maybe somebody cooler than me has better one
commented: thanks +3

IDLE is OK for quick check but now and then you should run the program directly from command line or double click the file. Or you can use text editor that can run the file externally, not redirected like IDLE. We should maybe check IDLE's code and add possibility to launch file in external interpreter.

My code must be run directly.

I really thank you guys, i will try and check this out. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.