Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function not returning random integer for variable

Tags:

python

random

I have a very simple problem, when I run the following code:

from random import randint

def create_random():
  x = random.randint(1,4)
  return x 

print(create_random)

The output comes to this:

< function create_random at 0x7f5994bd4f28 >

Note: every character between "0x7f" and "f28" are random each time the code is run.

My goal was to be able to call the function multiple times with x being assigned a new integer value between 1 and 3 with each invocation.

like image 294
Atronach41 Avatar asked Jun 28 '26 04:06

Atronach41


1 Answers

You aren't actually calling the function. To do this you need to do:

print(create_random())

Just now you're printing the reference to the function which isn't very helpful for you in this case.

like image 56
Tom Dee Avatar answered Jun 29 '26 17:06

Tom Dee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!