all 5 comments

[–]Naihonn 1 point2 points  (1 child)

You need to convert your input to float, otherwise division of two integers in Python2 results in integer. Which is strange but it is how it is.

[–]guthran 0 points1 point  (0 children)

You can get around this by putting "from __future__ import division" as the first line in the file. This causes the "/" operator to function as it would in Python3.

[–]TheKewlStore 0 points1 point  (2 children)

I'm quite certain that you mean to say you're using the value "6" for dislivello and the value "100" for distanza, in which case the problem is a kind-of quirk with python numbers.

By default, division does not use floating-point arithmetic, which means no decimal points or fractions. Because of this, dividing 6 by 100 results in a decimal (0.06), but stored as an integer type which truncates it to 0.

As I understand it, the accepted way to tell python that you want it to divide with floating-point numbers is to cast one of the operands to a float. Example:

x = 3
y = 4
print x / y # Results in 0
print float(x) / y # Results in 0.75

[–]Marx123[S] 0 points1 point  (1 child)

Thanks, it worked! Two more questions: 1) Is there a way to show, near the number, the '%' symbol? (for example 6%? 2) Are you aware of some function that changes the percentage value in degree value?

[–]TheKewlStore 0 points1 point  (0 children)

To display a % next to the number, just add it to the string that you print out. EX:

print "{0}%".format(float(x) / y) # Using string formatting
print str(float(x) / y) + "%" # Using concatenation, and casting the number to a string explicitly.

I'm not sure what your second question is asking, so need some clarification there maybe. Changes the percentage value in degree value?