Created
July 26, 2017 08:30
-
-
Save ashaindlin/17a2c45c2b3ed7c71d25696bb8568ec7 to your computer and use it in GitHub Desktop.
Calculate how far along you are in a knitting project, assuming linear rate of increases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
def calculate(castOn: int, bindOff: int, totalRows: int, curRow: int): | |
incPerRow = (bindOff - castOn)/totalRows; # stitches increased per row | |
totalStitches = sum([castOn + incPerRow*r for r in range(1, totalRows)]) | |
stitchesKnit = sum([castOn + incPerRow*r for r in range(1, curRow)]) | |
return int(100 * stitchesKnit / totalStitches) | |
if __name__ == "__main__": | |
c = int(input("Stitches cast on: ")) | |
b = int(input("Final stitch count: ")) | |
t = int(input("Total rows: ")) | |
r = int(input("Current row: ")) | |
print("You are roughly " + str(calculate(c, b, t, r)) + "% of the way done.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment