-1

I have the following method inside a class:

    def initialize_overlaps(self):
    """Initialize the overlap list for each band_nk """
    for n in range(self.nbands):
        for k in range(self.nkpts - 1):
            for n_prim in range(self.nbands):
                print("Currently overlapping n: " + str(n) + ". k: " +str(k) +". n': " +
                      str(n_prim) + "\t" +str(n/self.nbands) + " percent completed.")

When running it, the indices of the loops change fine, but I dont know why the operation n/self.nbands always yields zero:

Currently overlapping n: 3. k: 12. n': 10       0 percent completed.
Currently overlapping n: 3. k: 12. n': 11       0 percent completed.
Currently overlapping n: 3. k: 13. n': 0        0 percent completed.
Currently overlapping n: 3. k: 13. n': 1        0 percent completed.
Currently overlapping n: 3. k: 13. n': 2        0 percent completed.
Currently overlapping n: 3. k: 13. n': 3        0 percent completed.
Currently overlapping n: 3. k: 13. n': 4        0 percent completed.
Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
Joshua Salazar
  • 205
  • 4
  • 14

1 Answers1

1

This is because n is always smaller than self.nbands and therefore the pure / division is 0. You should convert one of the two values to float. The following substitution in the print statement would work

str(n/float(self.nbands))
kosnik
  • 2,342
  • 10
  • 23