Python getting user input and time usage



'''
Created on Aug 1, 2013
Python version > 3
@author: tunatore
'''
import time

#before python 3 please use raw_input() function instead
#refer to http://www.python.org/dev/peps/pep-3111/

#starting clock
startTime = time.clock()

stars = input('I will print stars tell me any number :')

#printing stars
for j in range(int(stars)+1):
    print ('*'*(j))

word = input('Tell me a word :')

#printing word
for j in range(int(len(word)+1)):
    print (word[j-1]*(j))

#stopping clock
stopTime = time.clock()

print ("You have been using this program for {0} seconds".format( stopTime - startTime))

Output

I will print stars tell me any number :10

*
**
***
****
*****
******
*******
********
*********
**********
Tell me a word :tuna

t
uu
nnn
aaaa
You have been using this program for 4.22824467283872 seconds

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s