I am currently in need of help on a piece of homework, I'm using python 3.3 and i need to set a delay on a times table program that i created heres the code:

def get_int(prompt="Enter an integer: "):
    """this function will loop until an integer is entered"""
    while True:
        try:
            # return breaks out of the endless while loop
            return int(input(prompt))
        except ValueError:
            print("Try again, value entered was not an integer.")
x = get_int ("Enter a number: ")
for i in range(1,13):
   print (x*i)

Is it possible to add a delay without changing the code dramatically or would i have to change everything? Thanks in advance.

Looks very clean way to input integer.

You mean something like this ...

import time

def get_int(prompt="Enter an integer: "):
    """this function will loop until an integer is entered"""
    while True:
        try:
            # return breaks out of the endless while loop
            return int(input(prompt))
        except ValueError:
            print("Try again, value entered was not an integer.")

x = get_int ("Enter a number: ")
for i in range(1,13):
   print(x*i)
   time.sleep(1.2)

Yea thats what i meant , didn't realise it was that simple, cheers!

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.