random.randrange

92 views
Skip to first unread message

ameliand rea

unread,
Feb 14, 2014, 5:01:33 AM2/14/14
to psychop...@googlegroups.com
Hi there!
I am a beginner and I am sure this is a beginners question...

I want to define x as a random number from a specific range --> x = random.randrange($lower_x, $upper_x, 1)
I defined lower_x and upper_x in a separate excel file.

This is the error message:
    x = random.randrange($lower_x, $upper_x, 1)
                         ^
SyntaxError: invalid syntax


When I replace 
$lower_x, $upper_x by numbers, it works.

What's wrong?

Thanks for your help!!

Jonas Lindeløv

unread,
Feb 14, 2014, 6:47:45 AM2/14/14
to psychop...@googlegroups.com
Looks like you're used to PHP programming. Variables are not prefixed with $ in python. Just do

lower = 2
upper = 6
x = random.randrange(lower, upper, 1)

Best,
Jonas

Jonathan Peirce

unread,
Feb 14, 2014, 7:25:04 AM2/14/14
to psychop...@googlegroups.com
Actually Jonas, this is probably a carry-over from Builder where the $
is used to differentiate literal values from code.
Ameliand, Jonas' advice is exactly correct. When you write into a code
component or script, you should omit any dollar signs. You only need
them in dialog box entries. :-)

x = random.randrange(lower_x, upper_x, 1)

On 14/02/2014 11:47, Jonas Lindeløv wrote:
> Looks like you're used to PHP programming. Variables are not prefixed
> with $ in python.

--
Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk

This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system, you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.




Jonas Lindeløv

unread,
Feb 14, 2014, 10:28:20 AM2/14/14
to psychop...@googlegroups.com
Doh! Yes that occurred to me a few minutes ago and I went here to correct myself. Thanks for clarifying!

Best,
Jonas

ameliand rea

unread,
Feb 18, 2014, 6:10:32 AM2/18/14
to psychop...@googlegroups.com

Hi!

Thanks so much for your help!!
I tried several things and strangely, the only thing working is:
rand.randrange(lower_x, upper_x, 1)

(not "random")

Thanks for your help and best regard
amelia
Reply all
Reply to author
Forward
0 new messages