Round

H

HeidiWeber

Hello

i´m a beginner in python. With version 14 in SPSS (statistic software)
there are the posibility to use python.

i want do the following:

double NCases
NCases=10/6

is this correct in python? Because in SPSS there are an error message.

Thank you very much
cu
Heidi
 
D

Diez B. Roggisch

HeidiWeber said:
Hello

i´m a beginner in python. With version 14 in SPSS (statistic software)
there are the posibility to use python.

i want do the following:

double NCases
NCases=10/6

is this correct in python? Because in SPSS there are an error message.

No, its not correct in python. In python, you don't declare the type of a
variable. You statement above would simply be

NCases = 10.0 / 6.0

Note the float-literals! If you wouldn't use these, the result would not be
~1.6, but 1 instead, because integer division yields only integers.

Depending on which version of python SPSS ships, you should be able to make
the division-operator / enforce the usage of floats by putting


from __future__ import division

on top of your script.

Diez
 
R

Ravi Teja

No! That is NOT correct Python. For one thing, you do not declare the
types in dynamically typed languages. Secondly, if you want floating
point division, you need to enter atleast one of the numbers as float.

For example
10.0/6
or
10./6
or
float(10)/6

You will find the following helpful.
http://www.ibiblio.org/obp/thinkCSpy/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,292
Messages
2,571,494
Members
48,179
Latest member
รับปั๊มไลค์|LikePro

Latest Threads

Top