Keshav Sota
Keshav Sota

Reputation: 1

Function not properly returning with a list

Working on this code. When the program runs, print(random_generator) doesn't actually print out the quote, it simply says <function 40x....> in the shell. Any tips as to why this is happening?

import time  
import random 
quotes= ["Life is too short, so savior every moment", 
"Here's to the crazy ones, the rebels, square pegs in round holes",       
"You miss all the shots you don't take"]



def random_generator():   #RandomQuoteGenerator
    return random.choice(quotes)

timeout = 1     #Timer 
first_time = time.time()
last_time = first_time
while(True):
    pass #do something here
    new_time = time.time()
    if  new_time - last_time > timeout:
        last_time = new_time
        print(random_generator) 
        print ("Its been %f seconds" % (new_time - first_time))  #TimeCheck

Upvotes: 0

Views: 51

Answers (1)

NJM
NJM

Reputation: 595

Also if you want to actually print the results of random_generator you need to actually call it.

You have:

print(random_generator)

You probably wanted:

print(random_generator())

Upvotes: 1

Related Questions