
[ad_1]
Pendulums are clocks by nature, and a little Python program makes it fun to calculate some fascinating things with them.

I’ve noticed some interesting things by looking out my large window at the deep blue day sky above the Denver skyline. Most balloons are of the small party type, usually accidentally dropped somewhere by a careless youngster. But one afternoon a high-altitude inverted tear-drop-shaped balloon appeared, similar to the Skyhook balloons from decades ago, as shown above.
I couldn’t tell how big the balloon was, but I could tell it was at great height. Its barely visible payload was hanging low and it was slowly swinging back and forth.
It suddenly dawned on me that I could measure balloons in a very unique way, even from such a distance. So I did. My rough but reasonable calculations showed that the payload was hanging 70 feet below the balloon at the end of a long tether.
Fast forward to tomorrow. I was sitting in a coffee shop located in an old antique firehall building near downtown Denver. Several chandelier-type lamps were hanging from very high ceilings, and I noticed one swinging back and forth a bit at times. I measured the length of the lamp using the same technique as I did with the balloon years ago, and it worked out to about 12 feet. (Yes, I was bored, but it helped pass the time gracefully!)
Both of those calculations of course used a simple formula for the swing time of a pendulum. It turns out that it doesn’t matter how heavy the mass is at the end of the string or chord. The duration of its swing depends only on the length of that string or string. You can calculate the period of a pendulum if you know its length, or the time it takes to swing back and forth once, or you can calculate its length if you know its period. can.
Here is the formula that summarizes these calculations, where T is the time for one full swing, or duration, for a pendulum, and L is the length of the string or chord. Note that g is the acceleration of gravity, which on Earth is about 9.8 meters per second.

Here’s my little Python program that lets you input either the duration of the swing, or the length of the swing, and the other will be calculated.
import mathprint("\nPENDULUM")
print("period in seconds")
print("length in meters")
print("\nEnter one value..\n")seconds = input(s := "Period: ")
seconds = float(seconds) if seconds else 0.0meters = input(m := "Length: ")
meters = float(meters) if meters else 0.0if seconds:
meters = 9.8 * (seconds / math.pi / 2) ** 2
else:
seconds = 2 * math.pi * (meters / 9.8) ** 0.5print()
print(s, seconds, "seconds")
print(m, meters, "meters")
print(m, meters * 100 / 30.48, "feet")
print(m, meters * 100 / 2.54, "inches")
python talking points
Take a look at the two lines of code where the user enters seconds. walrus operator :=
used to set named variables s
To "Period: "
So this string can be reused in the output lines at the end.
The next code line sets the value of seconds to a float value of the user’s type, or to zero if nothing was typed. This is a handy little input trick that I use for a lot of simple programs.
If seconds are the input, the length of the meter is calculated for the pendulum in question. Otherwise, the number of seconds is calculated for the period of the pendulum if meter length is input.
Note that the two lines of calculation use a double asterisk **
To find both the square root and the square root of the values. Raising a number to the power of 0.5 is the same as finding the square root. There is no need to import math module to do it this way, however in this program we need to import math anyway to access the value of pi.
As a working example, imagine you have some fishing string, a pocketknife, and a 3×5 note card, and you’re somewhere in the woods at the base of a very high rock that you want to measure.
After playing with this program at home, before going into the woods, you remember that a pendulum of 39 inches has a period of 2 seconds. Here’s what the sample count looks like using the program above…

Ok, here’s what you do to measure the height of the cliff.
When your friend climbs to the top of the cliff, you tie the rope to the pocketknife and measure the string to 39 inches (7 lengths of card, 1 width and 1/3 of its width).
Your friend drops a rock and you time the number of seconds it takes to hit the ground. Presto Magico, you have everything you need to calculate the height of the cliff! (I’ll leave the rest of that calculation for you to find out.)
words of caution
Be sure to watch carefully your friend, the pendulum and the rock. enough said.
[ad_2]
Source link
#Python #Shorts #Pendulum #Pendulums #natures #clocks #John #Clark #Craig #August