0

For a college assignment, I have been tasked with calculating the genotypes of approximately 200 generations, with the code stopping when BB is greater than .99 . I have checked in with my Professor, who stated that my code looked good but there is a breakpoint somewhere that is causing the program to not write anything other than the tabulate headings to the output file. I tried diagnosing the issue by putting several outputFile.write("Breakpoint") lines after each line in an attempt to find the issue (per my instructor's directives). Despite this, I am still unable to figure out why it is not outputting correctly.

I only want help figuring out exactly where/what the breakpoint is as I want to maintain as much academic honesty as possible since this is my major. I have been beating my head against the wall for the past several hours attempting to figure this out. Any help will be appreciated greatly!

https://pastebin.com/zKY8Zuu7

Sample Incomplete Output Table: (This is what the output should look like, but only the bold portion is outputting.) Generation AA AB BB ========= ==== ==== ==== 1 0.250 0.500 0.250 2 0.111 0.444 0.444

from tabulate import tabulate
outputFile = open("genotype.txt", 'w')
x = 0.25
y = 0.5
z = 0.25
g = 1
t = [["Generation", "AA Gene", "AB Gene", "BB Gene"]]
 
outputFile.write(tabulate(t))
while z < 0.99:
    table = [[g, x, y, z]]
    (tabulate(table, floatfmt=("10.0f", "7.3f", "7.3f", "7.3f")))
    p = 0.5 * (y / (y + z))
    x = p * p
    y = (2*p) * (1-p)
    z = (1-p) * (1-p)
    g = g+1
outputFile.close()

I tried executing the code and I am unable to figure out where the breakpoint is. It is not outputting anything to the table other than the bolded headings.

  • I don't think you're using the term "breakpoint" correctly. A breakpoint is a flag you can put on one or more lines of code, when running the code via a debugger; code execution pauses when a breakpoint is reached, so that you can examine the state of memory at that point. Maybe the term you're looking for is "bug". – Random Davis Mar 03 '23 at 18:07
  • Also the only time you ever write anything to `outputFile` is on the line `outputFile.write(tabulate(t))`. Nothing in the `while` loop looks like is writing to the output file. Is that what you mean by "no output"? – Random Davis Mar 03 '23 at 18:08
  • Apologies, I was just using the terminology that my instructor left in an email. I attempted to put an outputFile.write("Help") in the while loop in an attempt to get anything to output to the table, but I still found no luck. (I put that line with the same indentation at various points in the while loop, on their own lines); but I was still unable to get any output. Should the outputFile.write be on its own line or somewhere else? Thank you for helping me! I know this is probably a super obvious fix, but I appreciate the help. – TheCodeGoblin Mar 03 '23 at 18:55
  • Well the line `(tabulate(table, floatfmt=("10.0f", "7.3f", "7.3f", "7.3f")))` seems totally pointless as its output is not stored, printed, or passed to any functions (such as the function `outFile.write()`. So I would think that the very first thing you'd have to do is fix that. Then the second basic step is to make sure your loop is actually running. This is where a real breakpoint comes in handy; you can use a debugger to put a breakpoint right before the `while` loop, and then step through the next lines with the debugger to make sure the code is doing what you expect. – Random Davis Mar 03 '23 at 19:06
  • I debugged the loop and it's running nearly 200 times (`g` is `199` at the end). So, I think the issue is that you're just not writing anything to your output file. – Random Davis Mar 03 '23 at 19:09

0 Answers0