0

This is the code that I am running:

for x in range(0,90):
   print (x*(5/90))

for some reason, all it prints out are 0's. What am I doing wrong?

Thanks

Alex
  • 21,273
  • 10
  • 61
  • 73
M M
  • 1

4 Answers4

1

What's happening is that it is figuring that you really want Integers. Try change it to be:

print(x*(5.0/90))
David Hoelzer
  • 15,862
  • 4
  • 48
  • 67
0

try this instead

for x in range(0,90):
    print (5.* x/90))
farhawa
  • 10,120
  • 16
  • 49
  • 91
0

in python dividing an int by another int give an int so to get the float result you can simply add a ".0" behind any integer to avoid casting.

change it by

           for x in range(0,90): print (x*(5/90.0))
0

This should work:

for x in range(0,90): print (x*(5/90.0))

Python is interpreting the numbers as integers and therefore the result is 0

Alex
  • 21,273
  • 10
  • 61
  • 73