Newton's Laws

Newton's Laws of Motion

The following is copied verbatim from Wikipedia for the purposes of playing around with Mathjax.

Newton's laws of motion are three physical laws that form the basis for classical mechanics. They describe the relationship between the forces acting on a body and its motion due to those forces. They have been expressed in several different ways over nearly three centuries, and can be summarized as follows:

The three laws of motion were first compiled by Sir Isaac Newton in his work Philosophić Naturalis Principia Mathematica, first published in 1687. Newton used them to explain and investigate the motion of many physical objects and systems. For example, in the third volume of the text, Newton showed that these laws of motion, combined with his law of universal gravitation, explained Kepler's laws of planetary motion.

Newton's Laws of Gravitation

Again, what follows is from Wikipedia.

Newton's law of universal gravitation states that every point mass in the universe attracts every other point mass with a force that is directly proportional to the product of their masses and inversely proportional to the square of the distance between them. (Separately it was shown that large spherically symmetrical masses attract and are attracted as if all their mass were concentrated at their centers.) This is a general physical law derived from empirical observations by what Newton called induction. It is a part of classical mechanics and was formulated in Newton's work Philosophić Naturalis Principia Mathematica ("the Principia"), first published on 5 July 1687. (When Newton's book was presented in 1686 to the Royal Society, Robert Hooke made a claim that Newton had obtained the inverse square law from him – see History section below.) In modern language, the law states the following:

Every point mass attracts every single other point mass by a force pointing along the line intersecting both points. The force is proportional to the product of the two masses and inversely proportional to the square of the distance between them: $$F = G \frac{m_1 m_2}{r^2},$$ where:


The table below shows the SI units for the quantities involved in the above discussion.

Symbol Quantity Unit
$\mathbf{F}$ Force Newton ($N$)
$m$ Mass Kilogram ($kg$)
$\mathbf{a}$ Acceleration Metres per second${}^2$ ($ms^{-2}$)
$\mathbf{v}$ Velocity Metres per second ($ms^{-1}$)
$r$ Distance Metres ($m$)
$G$ Gravitational constant $N m^2 kg^{-2}$

Examples of Python code in webpages

Here's a link to a .py file, which can be downloaded by right-clicking and selecting 'save as'.

Here's what the code looks like using Google Prettify.

# an implementation of the game of higher or lower

from random import randint

number = randint(1, 100)

print("Higher or lower?")
print("Try to guess the number I've thought of between 1 and 100.")

attempts = 0
guess = 0

while guess != number:
    attempts += 1

    if attempts > 7:
        print("Hurry up!")

    attempt_number = str(attempts)
    guess = int(input("Guess "+attempt_number+": "))

    if guess > number:
        print(guess, "is too high")
    elif guess < number:
        print(guess, "is too low")

print("Correct! The answer was", guess)
print("You took", attempts, "attempts.")

if attempts > 8 and attempts < 11:
    print("Too slow for my liking!")
elif attempts > 10:
    print("Were you even trying?")

And here's embedded code using