top of page

02.22.2018: One Lesson of Python

Today's soundtrack is Struggle Jennings: I Am Struggle.

Rather than doing an actual lesson today, I'm going to try putting together a little program that will calculate approximately how many edge pieces a puzzle should have. I tried to work out the equation myself and was unsuccessful. Based on some research I did online on how to determine perimeter from area, combined with questions other people had asked about similar topics, I decided to go with the equation P=([√A]4.1)-4, with "P" representing the perimeter (edge) pieces, and "A" representing the area, or total number of puzzle pieces as listed on the box.

I immediately ran into problems trying to use the square root symbol. I learned that I must first import the math module (import math) then use math.sqrt() to determine a square root. Once I did that, I had trouble converting my input to an integer instead of a string. I finally found a solution on stack overflow: rather than just (input), I needed to use int(input().

Next, I wanted to give the user a message that would say "You have approximately X edge pieces," but I couldn't figure out how to integrate a variable and a string. On Stack Exchange, I found a solution: string formatting! I then used (round()) to round the answer to a nice clean answer.

Later on, I'd like to work more on this; I'd like to add a question at the end asking whether the user would like to calculate another puzzle, and if no, the program will close; however, I need to go to bed, so that will have to wait for another day. Still, I'm very happy with my progress today!


bottom of page