<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.physicsbook.gatech.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Adsouza</id>
	<title>Physics Book - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://www.physicsbook.gatech.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Adsouza"/>
	<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/Special:Contributions/Adsouza"/>
	<updated>2026-05-17T01:07:21Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.7</generator>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38900</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38900"/>
		<updated>2020-11-15T17:43:11Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
Python is an interpreted, high-level programming language. As a general-purpose language, it is used for a variety of applications, which makes it an obvious choice for computational physics models, considering its shallow learning curve and syntactically simplistic features. It is also OS-independent, allowing it to be run on virtually any machine. &lt;br /&gt;
&lt;br /&gt;
===VPython===&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although VPython slightly differs from the actual Python programming language, the majority of functionality remains the same, including all syntax. For the sole purpose of this class, however, it is functionally equivalent to Python, which is why it is imperative to understand the underlying Python language. Most of the labs done this year (which includes any labs requiring the construction of a physics simulation model) will be done using the VPython.&lt;br /&gt;
&lt;br /&gt;
==Downloading/Installation==&lt;br /&gt;
&lt;br /&gt;
===Versions===&lt;br /&gt;
Python has two major versions: Python 2 and 3&lt;br /&gt;
&lt;br /&gt;
However, on January 1st, 2020, version 2.x was officially deprecated and no longer officially supported by the Python Foundation. As a result, the majority of the Python community have already migrated away from the dying version. In any case, Python 2.x has significant syntactical differences that Python 3.x is not backwards-compatible with (hence, the major version change), which is why this course will be attempting to adhere to the guidelines set by Python 3.&lt;br /&gt;
&lt;br /&gt;
===Downloading===&lt;br /&gt;
The latest stable version of Python 3 available is [https://www.python.org/downloads/release/python-390/ 3.9.0] (as of November 2020).&lt;br /&gt;
&lt;br /&gt;
Older versions of Python 3 can be found at [https://www.python.org/downloads/ https://www.python.org/downloads/].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this class, it is not necessary to download and install VPython, as we will be working with VPython through the virtual [https://www.glowscript.org/ GlowScript] environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Downloading==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
Variables in Python are named items/containers that allow data to be stored (only during the execution of the program; after the program finishes, the variables are no longer retained). Python is an Object-Oriented Programming (OOP) language, which essentially means that the variables can be thought of as &amp;quot;objects,&amp;quot; or abstract data types representing various forms of information. For instance, &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; is a variable type that holds only integers (without any fractional values), while &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt; is another variable type that holds decimal values. Below is a list of common variable types in Python:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Integer&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Float (decimal)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3.25&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: String&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: List (modifiable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;[1, 3, 5, 7, 9]&amp;lt;/code&amp;gt;&lt;br /&gt;
** Something to note about indexing in Python is that the first element is always index 0, and the &#039;&#039;n&#039;&#039;th element is always index &#039;&#039;n&#039;&#039; - 1&lt;br /&gt;
* &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Tuple (immutable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;(1, 3, 5, 7, 9)&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Set (unordered collection of other variables/data types, cannot modify pre-existing elements, but can add new ones)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{3, 7, 9, 5, 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Dictionary/HashMap (unordered mapping of keys to values)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{&#039;b&#039;: 3, &#039;d&#039;: 7, &#039;e&#039;: 9, &#039;c&#039;: 5, &#039;a&#039;: 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variables are assigned with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals) operator. Unlike other programming languages, Python does not require explicit types to be defined when declaring variables; the types are inferred during runtime (as it is an interpreted language). Hence, the only information needed for assignment is the variable name and data to assign. Python variables can have any name, but it must start with a letter or underscore (although the underscore is generally reserved for library variables, so it is best to stick with letters), and can only contain alphanumeric characters and underscores (&amp;lt;code&amp;gt;A-z&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;0-9&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt;). Here are a few examples of variable assignment:&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 long_variable_name = [0, 1, 2, 3, 4]&lt;br /&gt;
 CAPITAL_VARIABLE_NAME = {&#039;apple&#039;, &#039;orange&#039;, &#039;banana&#039;}&lt;br /&gt;
 _starts_with_underscore = {&#039;yes&#039;: 1.0, &#039;no&#039;: 0.0}  # Try to avoid this type of naming if possible!&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
Operators are symbols used to perform mathematical manipulations and operations to data.&lt;br /&gt;
Some of the simplest mathematical operations include:&lt;br /&gt;
&lt;br /&gt;
 # Addition: &lt;br /&gt;
 1 + 2  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Subtraction: &lt;br /&gt;
 2 - 1  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Multiplication: &lt;br /&gt;
 2 * 1  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Division: &lt;br /&gt;
 2 / 1  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
There are other operations that are more complex than these, such as:&lt;br /&gt;
&lt;br /&gt;
 # Exponentiation: &lt;br /&gt;
 2 ** 2  # This will equal 4&lt;br /&gt;
 &lt;br /&gt;
 # Remainder: &lt;br /&gt;
 5 % 4  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Absolute value:&lt;br /&gt;
 abs(-3)  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Square root: &lt;br /&gt;
 sqrt(4)  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Euler&#039;s number:&lt;br /&gt;
 exp(1)  # This will equal e^1&lt;br /&gt;
&lt;br /&gt;
Another useful category of operators are known as assignment operators, which can be used to perform the specified mathematical operation on a variable, and then store the resulting value back into the variable. In order to use assignment operators, you must specify the variable name, followed by the operator symbol with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals sign), and finally the value. For instance, it is possible to add 3 to the value of x and store it in x again like so:&lt;br /&gt;
&lt;br /&gt;
 x = x + 3&lt;br /&gt;
&lt;br /&gt;
However, this statement could be simplified into:&lt;br /&gt;
&lt;br /&gt;
 x += 3&lt;br /&gt;
&lt;br /&gt;
This will be frequently used in physics simulation models, as variables often needed to be updated in this format.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;, you would code:&lt;br /&gt;
 print(&#039;Hello, world!&#039;)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
Another common use case for the print statement is to display a hard-coded string along with a variable. This can be done by casting the variable to a string and &amp;quot;adding&amp;quot; it to the hardcoded string:&lt;br /&gt;
&lt;br /&gt;
 s = &#039;Hello, world #&#039;&lt;br /&gt;
 number = 3&lt;br /&gt;
 print(s + str(number) + &#039;!&#039;)  # Hello, world #3!&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement, followed by a colon. The next line is indented, and then tells that &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement what to do if the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement is &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;. If it is not &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, it moves on to the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement. &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements are only used after &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statements, and cannot be used independently. There can be any number of &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements, but only one &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement. Notice this uses the same syntax as the regular if statement. Lastly, if neither the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; nor the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement(s) are &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, there is an &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement. There can also be only one &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement, though it is not required.&lt;br /&gt;
&lt;br /&gt;
Another important issue regarding &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; and other statements is the code block formatting. Other programming languages tend to use braces for code blocks like this, but in Python it is designated by indentation. This is why it is critical to ensure your program is formatted correctly.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
This is an example of using Python to implement a mathematical model.&lt;br /&gt;
For the gravitational principle, it is known that the force of gravity is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;|F_{G}| = G \frac{M_{1} M_{2}}{R^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can use this knowledge to create a variable called &amp;lt;code&amp;gt;gravitational_force&amp;lt;/code&amp;gt;, and assign it the magnitude of the gravitational force between objects &amp;lt;math&amp;gt;M_{1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;M_{2}&amp;lt;/math&amp;gt;. Given variables &amp;lt;code&amp;gt;m1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;m2&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;r&amp;lt;/code&amp;gt;, the Python code would be:&lt;br /&gt;
&lt;br /&gt;
 gravitational_force = 6.67 * 10 ** -11 * m1 * m2 / (r ** 2)&lt;br /&gt;
&lt;br /&gt;
Normally, in a Python physics model, we would have an outer loop that updates the variables and values for each iteration, which is where an update statement such as this would go. This could be used to determine the variable gravitational force on a skydiver jumping from a great height, as the force would not remain constant. In a finalized GlowScript model, this would look like:&lt;br /&gt;
&lt;br /&gt;
[https://trinket.io/embed/glowscript/7615a48c5f?start=result GlowScript Simulation]&lt;br /&gt;
&amp;lt;!--=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Connectedness==&lt;br /&gt;
As a high-level and syntactically simple language, Python is an excellent choice for the development of complex algorithms. Proficient knowledge of Python is critical to implementing machine learning algorithms, an emerging field that many computer science majors are interested in. Python could be used to efficiently employ these algorithms in industries such as stock market analysis, helping to understand trends in the way assets rise and fall.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
The concept of the Python programming language was developed in the late 1980s. In 1991, Guido van Rossum created the first version of the Python programming language, releasing it with the original intent of code readability (thanks to its use of whitespace and indentation).&lt;br /&gt;
&lt;br /&gt;
In 2000, Python 2 was released which contained several new backwards-incompatible features, such as list comprehension and a garbage collection system.&lt;br /&gt;
&lt;br /&gt;
The first version of Python 3 was released in 2008, while Python 2 was still in use, creating a rift between Python developers on version usage.&lt;br /&gt;
&lt;br /&gt;
Finally, on January 1st, 2020, Python 2 reached its end-of-life date, no longer officially supported by the Python Software Foundation.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [http://www.physicsbook.gatech.edu/VPython VPython] describes the basics of VPython and using it to create 3D models&lt;br /&gt;
* The [http://www.physicsbook.gatech.edu/GlowScript GlowScript] wiki page provides detailed instructions for how to use VPython on the GlowScript website&lt;br /&gt;
&lt;br /&gt;
===Further reading===&lt;br /&gt;
* These [https://wiki.python.org/moin/IntroductoryBooks Introductory Books] are a great resource for beginners looking to learn Python&lt;br /&gt;
* [https://www.freecodecamp.org/news/what-can-you-do-with-python-the-3-main-applications-518db9a68a78/ What exactly can you do with Python? Here are Python&#039;s 3 main applications]: This article provides several examples of industry applications of Python&lt;br /&gt;
* [https://towardsdatascience.com/how-to-build-your-own-neural-network-from-scratch-in-python-68998a08e4f6 How to build your own Neural Network from scratch in Python] gives a comprehensive guide on applying Python to machine learning&lt;br /&gt;
&lt;br /&gt;
===External links===&lt;br /&gt;
* For a more comprehensive guide with getting Python set up, go to [https://www.python.org/about/gettingstarted/ https://www.python.org/about/gettingstarted/]&lt;br /&gt;
* The [https://pypi.org/ Python Package Index] (PyPI) is a repository of community-created Python software packages that can be easily installed and used with Python code&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://www.python.org/about/ https://www.python.org/about/]&lt;br /&gt;
* [https://www.glowscript.org/docs/VPythonDocs/index.html https://www.glowscript.org/docs/VPythonDocs/index.html]&lt;br /&gt;
* [https://www.geeksforgeeks.org/history-of-python/ https://www.geeksforgeeks.org/history-of-python/]&lt;br /&gt;
* [https://docs.python.org/3/tutorial/ https://docs.python.org/3/tutorial/]&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38899</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38899"/>
		<updated>2020-11-15T17:42:54Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
Python is an interpreted, high-level programming language. As a general-purpose language, it is used for a variety of applications, which makes it an obvious choice for computational physics models, considering its shallow learning curve and syntactically simplistic features. It is also OS-independent, allowing it to be run on virtually any machine. &lt;br /&gt;
&lt;br /&gt;
===VPython===&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although VPython slightly differs from the actual Python programming language, the majority of functionality remains the same, including all syntax. For the sole purpose of this class, however, it is functionally equivalent to Python, which is why it is imperative to understand the underlying Python language. Most of the labs done this year (which includes any labs requiring the construction of a physics simulation model) will be done using the VPython.&lt;br /&gt;
&lt;br /&gt;
==Downloading/Installation==&lt;br /&gt;
&lt;br /&gt;
===Versions===&lt;br /&gt;
Python has two major versions: Python 2 and 3&lt;br /&gt;
&lt;br /&gt;
However, on January 1st, 2020, version 2.x was officially deprecated and no longer officially supported by the Python Foundation. As a result, the majority of the Python community have already migrated away from the dying version. In any case, Python 2.x has significant syntactical differences that Python 3.x is not backwards-compatible with (hence, the major version change), which is why this course will be attempting to adhere to the guidelines set by Python 3.&lt;br /&gt;
&lt;br /&gt;
===Downloading===&lt;br /&gt;
The latest stable version of Python 3 available is [https://www.python.org/downloads/release/python-390/ 3.9.0] (as of November 2020).&lt;br /&gt;
&lt;br /&gt;
Older versions of Python 3 can be found at [https://www.python.org/downloads/ https://www.python.org/downloads/].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this class, it is not necessary to download and install VPython, as we will be working with VPython through the virtual [https://www.glowscript.org/ GlowScript] environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Downloading==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
Variables in Python are named items/containers that allow data to be stored (only during the execution of the program; after the program finishes, the variables are no longer retained). Python is an Object-Oriented Programming (OOP) language, which essentially means that the variables can be thought of as &amp;quot;objects,&amp;quot; or abstract data types representing various forms of information. For instance, &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; is a variable type that holds only integers (without any fractional values), while &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt; is another variable type that holds decimal values. Below is a list of common variable types in Python:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Integer&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Float (decimal)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3.25&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: String&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: List (modifiable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;[1, 3, 5, 7, 9]&amp;lt;/code&amp;gt;&lt;br /&gt;
** Something to note about indexing in Python is that the first element is always index 0, and the &#039;&#039;n&#039;&#039;th element is always index &#039;&#039;n&#039;&#039; - 1&lt;br /&gt;
* &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Tuple (immutable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;(1, 3, 5, 7, 9)&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Set (unordered collection of other variables/data types, cannot modify pre-existing elements, but can add new ones)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{3, 7, 9, 5, 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Dictionary/HashMap (unordered mapping of keys to values)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{&#039;b&#039;: 3, &#039;d&#039;: 7, &#039;e&#039;: 9, &#039;c&#039;: 5, &#039;a&#039;: 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variables are assigned with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals) operator. Unlike other programming languages, Python does not require explicit types to be defined when declaring variables; the types are inferred during runtime (as it is an interpreted language). Hence, the only information needed for assignment is the variable name and data to assign. Python variables can have any name, but it must start with a letter or underscore (although the underscore is generally reserved for library variables, so it is best to stick with letters), and can only contain alphanumeric characters and underscores (&amp;lt;code&amp;gt;A-z&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;0-9&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt;). Here are a few examples of variable assignment:&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 long_variable_name = [0, 1, 2, 3, 4]&lt;br /&gt;
 CAPITAL_VARIABLE_NAME = {&#039;apple&#039;, &#039;orange&#039;, &#039;banana&#039;}&lt;br /&gt;
 _starts_with_underscore = {&#039;yes&#039;: 1.0, &#039;no&#039;: 0.0}  # Try to avoid this type of naming if possible!&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
Operators are symbols used to perform mathematical manipulations and operations to data.&lt;br /&gt;
Some of the simplest mathematical operations include:&lt;br /&gt;
&lt;br /&gt;
 # Addition: &lt;br /&gt;
 1 + 2  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Subtraction: &lt;br /&gt;
 2 - 1  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Multiplication: &lt;br /&gt;
 2 * 1  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Division: &lt;br /&gt;
 2 / 1  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
There are other operations that are more complex than these, such as:&lt;br /&gt;
&lt;br /&gt;
 # Exponentiation: &lt;br /&gt;
 2 ** 2  # This will equal 4&lt;br /&gt;
 &lt;br /&gt;
 # Remainder: &lt;br /&gt;
 5 % 4  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Absolute value:&lt;br /&gt;
 abs(-3)  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Square root: &lt;br /&gt;
 sqrt(4)  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Euler&#039;s number:&lt;br /&gt;
 exp(1)  # This will equal e^1&lt;br /&gt;
&lt;br /&gt;
Another useful category of operators are known as assignment operators, which can be used to perform the specified mathematical operation on a variable, and then store the resulting value back into the variable. In order to use assignment operators, you must specify the variable name, followed by the operator symbol with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals sign), and finally the value. For instance, it is possible to add 3 to the value of x and store it in x again like so:&lt;br /&gt;
&lt;br /&gt;
 x = x + 3&lt;br /&gt;
&lt;br /&gt;
However, this statement could be simplified into:&lt;br /&gt;
&lt;br /&gt;
 x += 3&lt;br /&gt;
&lt;br /&gt;
This will be frequently used in physics simulation models, as variables often needed to be updated in this format.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;, you would code:&lt;br /&gt;
 print(&#039;Hello, world!&#039;)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
Another common use case for the print statement is to display a hard-coded string along with a variable. This can be done by casting the variable to a string and &amp;quot;adding&amp;quot; it to the hardcoded string:&lt;br /&gt;
&lt;br /&gt;
 s = &#039;Hello, world #&#039;&lt;br /&gt;
 number = 3&lt;br /&gt;
 print(s + str(number) + &#039;!&#039;)  # Hello, world #3!&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement, followed by a colon. The next line is indented, and then tells that &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement what to do if the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement is &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;. If it is not &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, it moves on to the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement. &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements are only used after &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statements, and cannot be used independently. There can be any number of &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements, but only one &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement. Notice this uses the same syntax as the regular if statement. Lastly, if neither the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; nor the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement(s) are &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, there is an &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement. There can also be only one &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement, though it is not required.&lt;br /&gt;
&lt;br /&gt;
Another important issue regarding &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; and other statements is the code block formatting. Other programming languages tend to use braces for code blocks like this, but in Python it is designated by indentation. This is why it is critical to ensure your program is formatted correctly.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
This is an example of using Python to implement a mathematical model.&lt;br /&gt;
For the gravitational principle, it is known that the force of gravity is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;|F_{G}| = G \frac{M_{1} M_{2}}{R^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can use this knowledge to create a variable called &amp;lt;code&amp;gt;gravitational_force&amp;lt;/code&amp;gt;, and assign it the magnitude of the gravitational force between objects &amp;lt;math&amp;gt;M_{1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;M_{2}&amp;lt;/math&amp;gt;. Given variables &amp;lt;code&amp;gt;m1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;m2&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;r&amp;lt;/code&amp;gt;, the Python code would be:&lt;br /&gt;
&lt;br /&gt;
 gravitational_force = 6.67 * 10 ** -11 * m1 * m2 / (r ** 2)&lt;br /&gt;
&lt;br /&gt;
Normally, in a Python physics model, we would have an outer loop that updates the variables and values for each iteration, which is where an update statement such as this would go. This could be used to determine the variable gravitational force on a skydiver jumping from a great height, as the force would not remain constant. In a finalized GlowScript model, this would look like:&lt;br /&gt;
&lt;br /&gt;
[https://trinket.io/embed/glowscript/7615a48c5f?outputOnly=true&amp;amp;start=result GlowScript Simulation]&lt;br /&gt;
&amp;lt;!--=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Connectedness==&lt;br /&gt;
As a high-level and syntactically simple language, Python is an excellent choice for the development of complex algorithms. Proficient knowledge of Python is critical to implementing machine learning algorithms, an emerging field that many computer science majors are interested in. Python could be used to efficiently employ these algorithms in industries such as stock market analysis, helping to understand trends in the way assets rise and fall.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
The concept of the Python programming language was developed in the late 1980s. In 1991, Guido van Rossum created the first version of the Python programming language, releasing it with the original intent of code readability (thanks to its use of whitespace and indentation).&lt;br /&gt;
&lt;br /&gt;
In 2000, Python 2 was released which contained several new backwards-incompatible features, such as list comprehension and a garbage collection system.&lt;br /&gt;
&lt;br /&gt;
The first version of Python 3 was released in 2008, while Python 2 was still in use, creating a rift between Python developers on version usage.&lt;br /&gt;
&lt;br /&gt;
Finally, on January 1st, 2020, Python 2 reached its end-of-life date, no longer officially supported by the Python Software Foundation.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [http://www.physicsbook.gatech.edu/VPython VPython] describes the basics of VPython and using it to create 3D models&lt;br /&gt;
* The [http://www.physicsbook.gatech.edu/GlowScript GlowScript] wiki page provides detailed instructions for how to use VPython on the GlowScript website&lt;br /&gt;
&lt;br /&gt;
===Further reading===&lt;br /&gt;
* These [https://wiki.python.org/moin/IntroductoryBooks Introductory Books] are a great resource for beginners looking to learn Python&lt;br /&gt;
* [https://www.freecodecamp.org/news/what-can-you-do-with-python-the-3-main-applications-518db9a68a78/ What exactly can you do with Python? Here are Python&#039;s 3 main applications]: This article provides several examples of industry applications of Python&lt;br /&gt;
* [https://towardsdatascience.com/how-to-build-your-own-neural-network-from-scratch-in-python-68998a08e4f6 How to build your own Neural Network from scratch in Python] gives a comprehensive guide on applying Python to machine learning&lt;br /&gt;
&lt;br /&gt;
===External links===&lt;br /&gt;
* For a more comprehensive guide with getting Python set up, go to [https://www.python.org/about/gettingstarted/ https://www.python.org/about/gettingstarted/]&lt;br /&gt;
* The [https://pypi.org/ Python Package Index] (PyPI) is a repository of community-created Python software packages that can be easily installed and used with Python code&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://www.python.org/about/ https://www.python.org/about/]&lt;br /&gt;
* [https://www.glowscript.org/docs/VPythonDocs/index.html https://www.glowscript.org/docs/VPythonDocs/index.html]&lt;br /&gt;
* [https://www.geeksforgeeks.org/history-of-python/ https://www.geeksforgeeks.org/history-of-python/]&lt;br /&gt;
* [https://docs.python.org/3/tutorial/ https://docs.python.org/3/tutorial/]&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38898</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38898"/>
		<updated>2020-11-15T17:26:19Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: Added examples&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
Python is an interpreted, high-level programming language. As a general-purpose language, it is used for a variety of applications, which makes it an obvious choice for computational physics models, considering its shallow learning curve and syntactically simplistic features. It is also OS-independent, allowing it to be run on virtually any machine. &lt;br /&gt;
&lt;br /&gt;
===VPython===&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although VPython slightly differs from the actual Python programming language, the majority of functionality remains the same, including all syntax. For the sole purpose of this class, however, it is functionally equivalent to Python, which is why it is imperative to understand the underlying Python language. Most of the labs done this year (which includes any labs requiring the construction of a physics simulation model) will be done using the VPython.&lt;br /&gt;
&lt;br /&gt;
==Downloading/Installation==&lt;br /&gt;
&lt;br /&gt;
===Versions===&lt;br /&gt;
Python has two major versions: Python 2 and 3&lt;br /&gt;
&lt;br /&gt;
However, on January 1st, 2020, version 2.x was officially deprecated and no longer officially supported by the Python Foundation. As a result, the majority of the Python community have already migrated away from the dying version. In any case, Python 2.x has significant syntactical differences that Python 3.x is not backwards-compatible with (hence, the major version change), which is why this course will be attempting to adhere to the guidelines set by Python 3.&lt;br /&gt;
&lt;br /&gt;
===Downloading===&lt;br /&gt;
The latest stable version of Python 3 available is [https://www.python.org/downloads/release/python-390/ 3.9.0] (as of November 2020).&lt;br /&gt;
&lt;br /&gt;
Older versions of Python 3 can be found at [https://www.python.org/downloads/ https://www.python.org/downloads/].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this class, it is not necessary to download and install VPython, as we will be working with VPython through the virtual [https://www.glowscript.org/ GlowScript] environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Downloading==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
Variables in Python are named items/containers that allow data to be stored (only during the execution of the program; after the program finishes, the variables are no longer retained). Python is an Object-Oriented Programming (OOP) language, which essentially means that the variables can be thought of as &amp;quot;objects,&amp;quot; or abstract data types representing various forms of information. For instance, &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; is a variable type that holds only integers (without any fractional values), while &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt; is another variable type that holds decimal values. Below is a list of common variable types in Python:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Integer&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Float (decimal)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3.25&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: String&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: List (modifiable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;[1, 3, 5, 7, 9]&amp;lt;/code&amp;gt;&lt;br /&gt;
** Something to note about indexing in Python is that the first element is always index 0, and the &#039;&#039;n&#039;&#039;th element is always index &#039;&#039;n&#039;&#039; - 1&lt;br /&gt;
* &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Tuple (immutable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;(1, 3, 5, 7, 9)&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Set (unordered collection of other variables/data types, cannot modify pre-existing elements, but can add new ones)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{3, 7, 9, 5, 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Dictionary/HashMap (unordered mapping of keys to values)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{&#039;b&#039;: 3, &#039;d&#039;: 7, &#039;e&#039;: 9, &#039;c&#039;: 5, &#039;a&#039;: 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variables are assigned with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals) operator. Unlike other programming languages, Python does not require explicit types to be defined when declaring variables; the types are inferred during runtime (as it is an interpreted language). Hence, the only information needed for assignment is the variable name and data to assign. Python variables can have any name, but it must start with a letter or underscore (although the underscore is generally reserved for library variables, so it is best to stick with letters), and can only contain alphanumeric characters and underscores (&amp;lt;code&amp;gt;A-z&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;0-9&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt;). Here are a few examples of variable assignment:&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 long_variable_name = [0, 1, 2, 3, 4]&lt;br /&gt;
 CAPITAL_VARIABLE_NAME = {&#039;apple&#039;, &#039;orange&#039;, &#039;banana&#039;}&lt;br /&gt;
 _starts_with_underscore = {&#039;yes&#039;: 1.0, &#039;no&#039;: 0.0}  # Try to avoid this type of naming if possible!&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
Operators are symbols used to perform mathematical manipulations and operations to data.&lt;br /&gt;
Some of the simplest mathematical operations include:&lt;br /&gt;
&lt;br /&gt;
 # Addition: &lt;br /&gt;
 1 + 2  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Subtraction: &lt;br /&gt;
 2 - 1  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Multiplication: &lt;br /&gt;
 2 * 1  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Division: &lt;br /&gt;
 2 / 1  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
There are other operations that are more complex than these, such as:&lt;br /&gt;
&lt;br /&gt;
 # Exponentiation: &lt;br /&gt;
 2 ** 2  # This will equal 4&lt;br /&gt;
 &lt;br /&gt;
 # Remainder: &lt;br /&gt;
 5 % 4  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Absolute value:&lt;br /&gt;
 abs(-3)  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Square root: &lt;br /&gt;
 sqrt(4)  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Euler&#039;s number:&lt;br /&gt;
 exp(1)  # This will equal e^1&lt;br /&gt;
&lt;br /&gt;
Another useful category of operators are known as assignment operators, which can be used to perform the specified mathematical operation on a variable, and then store the resulting value back into the variable. In order to use assignment operators, you must specify the variable name, followed by the operator symbol with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals sign), and finally the value. For instance, it is possible to add 3 to the value of x and store it in x again like so:&lt;br /&gt;
&lt;br /&gt;
 x = x + 3&lt;br /&gt;
&lt;br /&gt;
However, this statement could be simplified into:&lt;br /&gt;
&lt;br /&gt;
 x += 3&lt;br /&gt;
&lt;br /&gt;
This will be frequently used in physics simulation models, as variables often needed to be updated in this format.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;, you would code:&lt;br /&gt;
 print(&#039;Hello, world!&#039;)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
Another common use case for the print statement is to display a hard-coded string along with a variable. This can be done by casting the variable to a string and &amp;quot;adding&amp;quot; it to the hardcoded string:&lt;br /&gt;
&lt;br /&gt;
 s = &#039;Hello, world #&#039;&lt;br /&gt;
 number = 3&lt;br /&gt;
 print(s + str(number) + &#039;!&#039;)  # Hello, world #3!&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement, followed by a colon. The next line is indented, and then tells that &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement what to do if the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement is &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;. If it is not &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, it moves on to the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement. &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements are only used after &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statements, and cannot be used independently. There can be any number of &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements, but only one &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement. Notice this uses the same syntax as the regular if statement. Lastly, if neither the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; nor the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement(s) are &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, there is an &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement. There can also be only one &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement, though it is not required.&lt;br /&gt;
&lt;br /&gt;
Another important issue regarding &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; and other statements is the code block formatting. Other programming languages tend to use braces for code blocks like this, but in Python it is designated by indentation. This is why it is critical to ensure your program is formatted correctly.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
This is an example of using Python to implement a mathematical model.&lt;br /&gt;
For the gravitational principle, it is known that the force of gravity is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;|F_{G}| = G \frac{M_{1} M_{2}}{R^{2}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can use this knowledge to create a variable called &amp;lt;code&amp;gt;gravitational_force&amp;lt;/code&amp;gt;, and assign it the magnitude of the gravitational force between objects &amp;lt;math&amp;gt;M_{1}&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;M_{2}&amp;lt;/math&amp;gt;. Given variables &amp;lt;code&amp;gt;m1&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;m2&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;r&amp;lt;/code&amp;gt;, the Python code would be:&lt;br /&gt;
&lt;br /&gt;
 gravitational_force = 6.67 * 10 ** -11 * m1 * m2 / (r ** 2)&lt;br /&gt;
&lt;br /&gt;
Normally, in a Python physics model, we would have an outer loop that updates the variables and values for each iteration, which is where an update statement such as this would go. This could be used to determine the variable gravitational force on a skydiver jumping from a great height, as the force would not remain constant. In a finalized GlowScript model, this would look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Connectedness==&lt;br /&gt;
As a high-level and syntactically simple language, Python is an excellent choice for the development of complex algorithms. Proficient knowledge of Python is critical to implementing machine learning algorithms, an emerging field that many computer science majors are interested in. Python could be used to efficiently employ these algorithms in industries such as stock market analysis, helping to understand trends in the way assets rise and fall.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
The concept of the Python programming language was developed in the late 1980s. In 1991, Guido van Rossum created the first version of the Python programming language, releasing it with the original intent of code readability (thanks to its use of whitespace and indentation).&lt;br /&gt;
&lt;br /&gt;
In 2000, Python 2 was released which contained several new backwards-incompatible features, such as list comprehension and a garbage collection system.&lt;br /&gt;
&lt;br /&gt;
The first version of Python 3 was released in 2008, while Python 2 was still in use, creating a rift between Python developers on version usage.&lt;br /&gt;
&lt;br /&gt;
Finally, on January 1st, 2020, Python 2 reached its end-of-life date, no longer officially supported by the Python Software Foundation.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [http://www.physicsbook.gatech.edu/VPython VPython] describes the basics of VPython and using it to create 3D models&lt;br /&gt;
* The [http://www.physicsbook.gatech.edu/GlowScript GlowScript] wiki page provides detailed instructions for how to use VPython on the GlowScript website&lt;br /&gt;
&lt;br /&gt;
===Further reading===&lt;br /&gt;
* These [https://wiki.python.org/moin/IntroductoryBooks Introductory Books] are a great resource for beginners looking to learn Python&lt;br /&gt;
* [https://www.freecodecamp.org/news/what-can-you-do-with-python-the-3-main-applications-518db9a68a78/ What exactly can you do with Python? Here are Python&#039;s 3 main applications]: This article provides several examples of industry applications of Python&lt;br /&gt;
* [https://towardsdatascience.com/how-to-build-your-own-neural-network-from-scratch-in-python-68998a08e4f6 How to build your own Neural Network from scratch in Python] gives a comprehensive guide on applying Python to machine learning&lt;br /&gt;
&lt;br /&gt;
===External links===&lt;br /&gt;
* For a more comprehensive guide with getting Python set up, go to [https://www.python.org/about/gettingstarted/ https://www.python.org/about/gettingstarted/]&lt;br /&gt;
* The [https://pypi.org/ Python Package Index] (PyPI) is a repository of community-created Python software packages that can be easily installed and used with Python code&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://www.python.org/about/ https://www.python.org/about/]&lt;br /&gt;
* [https://www.glowscript.org/docs/VPythonDocs/index.html https://www.glowscript.org/docs/VPythonDocs/index.html]&lt;br /&gt;
* [https://www.geeksforgeeks.org/history-of-python/ https://www.geeksforgeeks.org/history-of-python/]&lt;br /&gt;
* [https://docs.python.org/3/tutorial/ https://docs.python.org/3/tutorial/]&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38897</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38897"/>
		<updated>2020-11-15T17:09:15Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: Added references&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
Python is an interpreted, high-level programming language. As a general-purpose language, it is used for a variety of applications, which makes it an obvious choice for computational physics models, considering its shallow learning curve and syntactically simplistic features. It is also OS-independent, allowing it to be run on virtually any machine. &lt;br /&gt;
&lt;br /&gt;
===VPython===&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although VPython slightly differs from the actual Python programming language, the majority of functionality remains the same, including all syntax. For the sole purpose of this class, however, it is functionally equivalent to Python, which is why it is imperative to understand the underlying Python language. Most of the labs done this year (which includes any labs requiring the construction of a physics simulation model) will be done using the VPython.&lt;br /&gt;
&lt;br /&gt;
==Downloading/Installation==&lt;br /&gt;
&lt;br /&gt;
===Versions===&lt;br /&gt;
Python has two major versions: Python 2 and 3&lt;br /&gt;
&lt;br /&gt;
However, on January 1st, 2020, version 2.x was officially deprecated and no longer officially supported by the Python Foundation. As a result, the majority of the Python community have already migrated away from the dying version. In any case, Python 2.x has significant syntactical differences that Python 3.x is not backwards-compatible with (hence, the major version change), which is why this course will be attempting to adhere to the guidelines set by Python 3.&lt;br /&gt;
&lt;br /&gt;
===Downloading===&lt;br /&gt;
The latest stable version of Python 3 available is [https://www.python.org/downloads/release/python-390/ 3.9.0] (as of November 2020).&lt;br /&gt;
&lt;br /&gt;
Older versions of Python 3 can be found at [https://www.python.org/downloads/ https://www.python.org/downloads/].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this class, it is not necessary to download and install VPython, as we will be working with VPython through the virtual [https://www.glowscript.org/ GlowScript] environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Downloading==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
Variables in Python are named items/containers that allow data to be stored (only during the execution of the program; after the program finishes, the variables are no longer retained). Python is an Object-Oriented Programming (OOP) language, which essentially means that the variables can be thought of as &amp;quot;objects,&amp;quot; or abstract data types representing various forms of information. For instance, &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; is a variable type that holds only integers (without any fractional values), while &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt; is another variable type that holds decimal values. Below is a list of common variable types in Python:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Integer&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Float (decimal)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3.25&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: String&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: List (modifiable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;[1, 3, 5, 7, 9]&amp;lt;/code&amp;gt;&lt;br /&gt;
** Something to note about indexing in Python is that the first element is always index 0, and the &#039;&#039;n&#039;&#039;th element is always index &#039;&#039;n&#039;&#039; - 1&lt;br /&gt;
* &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Tuple (immutable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;(1, 3, 5, 7, 9)&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Set (unordered collection of other variables/data types, cannot modify pre-existing elements, but can add new ones)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{3, 7, 9, 5, 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Dictionary/HashMap (unordered mapping of keys to values)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{&#039;b&#039;: 3, &#039;d&#039;: 7, &#039;e&#039;: 9, &#039;c&#039;: 5, &#039;a&#039;: 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variables are assigned with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals) operator. Unlike other programming languages, Python does not require explicit types to be defined when declaring variables; the types are inferred during runtime (as it is an interpreted language). Hence, the only information needed for assignment is the variable name and data to assign. Python variables can have any name, but it must start with a letter or underscore (although the underscore is generally reserved for library variables, so it is best to stick with letters), and can only contain alphanumeric characters and underscores (&amp;lt;code&amp;gt;A-z&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;0-9&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt;). Here are a few examples of variable assignment:&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 long_variable_name = [0, 1, 2, 3, 4]&lt;br /&gt;
 CAPITAL_VARIABLE_NAME = {&#039;apple&#039;, &#039;orange&#039;, &#039;banana&#039;}&lt;br /&gt;
 _starts_with_underscore = {&#039;yes&#039;: 1.0, &#039;no&#039;: 0.0}  # Try to avoid this type of naming if possible!&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
Operators are symbols used to perform mathematical manipulations and operations to data.&lt;br /&gt;
Some of the simplest mathematical operations include:&lt;br /&gt;
&lt;br /&gt;
 # Addition: &lt;br /&gt;
 1 + 2  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Subtraction: &lt;br /&gt;
 2 - 1  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Multiplication: &lt;br /&gt;
 2 * 1  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Division: &lt;br /&gt;
 2 / 1  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
There are other operations that are more complex than these, such as:&lt;br /&gt;
&lt;br /&gt;
 # Exponentiation: &lt;br /&gt;
 2 ** 2  # This will equal 4&lt;br /&gt;
 &lt;br /&gt;
 # Remainder: &lt;br /&gt;
 5 % 4  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Absolute value:&lt;br /&gt;
 abs(-3)  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Square root: &lt;br /&gt;
 sqrt(4)  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Euler&#039;s number:&lt;br /&gt;
 exp(1)  # This will equal e^1&lt;br /&gt;
&lt;br /&gt;
Another useful category of operators are known as assignment operators, which can be used to perform the specified mathematical operation on a variable, and then store the resulting value back into the variable. In order to use assignment operators, you must specify the variable name, followed by the operator symbol with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals sign), and finally the value. For instance, it is possible to add 3 to the value of x and store it in x again like so:&lt;br /&gt;
&lt;br /&gt;
 x = x + 3&lt;br /&gt;
&lt;br /&gt;
However, this statement could be simplified into:&lt;br /&gt;
&lt;br /&gt;
 x += 3&lt;br /&gt;
&lt;br /&gt;
This will be frequently used in physics simulation models, as variables often needed to be updated in this format.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;, you would code:&lt;br /&gt;
 print(&#039;Hello, world!&#039;)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
Another common use case for the print statement is to display a hard-coded string along with a variable. This can be done by casting the variable to a string and &amp;quot;adding&amp;quot; it to the hardcoded string:&lt;br /&gt;
&lt;br /&gt;
 s = &#039;Hello, world #&#039;&lt;br /&gt;
 number = 3&lt;br /&gt;
 print(s + str(number) + &#039;!&#039;)  # Hello, world #3!&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement, followed by a colon. The next line is indented, and then tells that &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement what to do if the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement is &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;. If it is not &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, it moves on to the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement. &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements are only used after &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statements, and cannot be used independently. There can be any number of &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements, but only one &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement. Notice this uses the same syntax as the regular if statement. Lastly, if neither the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; nor the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement(s) are &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, there is an &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement. There can also be only one &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement, though it is not required.&lt;br /&gt;
&lt;br /&gt;
Another important issue regarding &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; and other statements is the code block formatting. Other programming languages tend to use braces for code blocks like this, but in Python it is designated by indentation. This is why it is critical to ensure your program is formatted correctly.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Connectedness==&lt;br /&gt;
As a high-level and syntactically simple language, Python is an excellent choice for the development of complex algorithms. Proficient knowledge of Python is critical to implementing machine learning algorithms, an emerging field that many computer science majors are interested in. Python could be used to efficiently employ these algorithms in industries such as stock market analysis, helping to understand trends in the way assets rise and fall.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
The concept of the Python programming language was developed in the late 1980s. In 1991, Guido van Rossum created the first version of the Python programming language, releasing it with the original intent of code readability (thanks to its use of whitespace and indentation).&lt;br /&gt;
&lt;br /&gt;
In 2000, Python 2 was released which contained several new backwards-incompatible features, such as list comprehension and a garbage collection system.&lt;br /&gt;
&lt;br /&gt;
The first version of Python 3 was released in 2008, while Python 2 was still in use, creating a rift between Python developers on version usage.&lt;br /&gt;
&lt;br /&gt;
Finally, on January 1st, 2020, Python 2 reached its end-of-life date, no longer officially supported by the Python Software Foundation.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [http://www.physicsbook.gatech.edu/VPython VPython] describes the basics of VPython and using it to create 3D models&lt;br /&gt;
* The [http://www.physicsbook.gatech.edu/GlowScript GlowScript] wiki page provides detailed instructions for how to use VPython on the GlowScript website&lt;br /&gt;
&lt;br /&gt;
===Further reading===&lt;br /&gt;
* These [https://wiki.python.org/moin/IntroductoryBooks Introductory Books] are a great resource for beginners looking to learn Python&lt;br /&gt;
* [https://www.freecodecamp.org/news/what-can-you-do-with-python-the-3-main-applications-518db9a68a78/ What exactly can you do with Python? Here are Python&#039;s 3 main applications]: This article provides several examples of industry applications of Python&lt;br /&gt;
* [https://towardsdatascience.com/how-to-build-your-own-neural-network-from-scratch-in-python-68998a08e4f6 How to build your own Neural Network from scratch in Python] gives a comprehensive guide on applying Python to machine learning&lt;br /&gt;
&lt;br /&gt;
===External links===&lt;br /&gt;
* For a more comprehensive guide with getting Python set up, go to [https://www.python.org/about/gettingstarted/ https://www.python.org/about/gettingstarted/]&lt;br /&gt;
* The [https://pypi.org/ Python Package Index] (PyPI) is a repository of community-created Python software packages that can be easily installed and used with Python code&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
* [https://www.python.org/about/ https://www.python.org/about/]&lt;br /&gt;
* [https://www.geeksforgeeks.org/history-of-python/ https://www.geeksforgeeks.org/history-of-python/]&lt;br /&gt;
* [https://docs.python.org/3/tutorial/ https://docs.python.org/3/tutorial/]&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38896</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38896"/>
		<updated>2020-11-15T17:04:32Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: Added history and see also sections&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
Python is an interpreted, high-level programming language. As a general-purpose language, it is used for a variety of applications, which makes it an obvious choice for computational physics models, considering its shallow learning curve and syntactically simplistic features. It is also OS-independent, allowing it to be run on virtually any machine. &lt;br /&gt;
&lt;br /&gt;
===VPython===&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although VPython slightly differs from the actual Python programming language, the majority of functionality remains the same, including all syntax. For the sole purpose of this class, however, it is functionally equivalent to Python, which is why it is imperative to understand the underlying Python language. Most of the labs done this year (which includes any labs requiring the construction of a physics simulation model) will be done using the VPython.&lt;br /&gt;
&lt;br /&gt;
==Downloading/Installation==&lt;br /&gt;
&lt;br /&gt;
===Versions===&lt;br /&gt;
Python has two major versions: Python 2 and 3&lt;br /&gt;
&lt;br /&gt;
However, on January 1st, 2020, version 2.x was officially deprecated and no longer officially supported by the Python Foundation. As a result, the majority of the Python community have already migrated away from the dying version. In any case, Python 2.x has significant syntactical differences that Python 3.x is not backwards-compatible with (hence, the major version change), which is why this course will be attempting to adhere to the guidelines set by Python 3.&lt;br /&gt;
&lt;br /&gt;
===Downloading===&lt;br /&gt;
The latest stable version of Python 3 available is [https://www.python.org/downloads/release/python-390/ 3.9.0] (as of November 2020).&lt;br /&gt;
&lt;br /&gt;
Older versions of Python 3 can be found at [https://www.python.org/downloads/ https://www.python.org/downloads/].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this class, it is not necessary to download and install VPython, as we will be working with VPython through the virtual [https://www.glowscript.org/ GlowScript] environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Downloading==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
Variables in Python are named items/containers that allow data to be stored (only during the execution of the program; after the program finishes, the variables are no longer retained). Python is an Object-Oriented Programming (OOP) language, which essentially means that the variables can be thought of as &amp;quot;objects,&amp;quot; or abstract data types representing various forms of information. For instance, &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; is a variable type that holds only integers (without any fractional values), while &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt; is another variable type that holds decimal values. Below is a list of common variable types in Python:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Integer&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Float (decimal)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3.25&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: String&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: List (modifiable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;[1, 3, 5, 7, 9]&amp;lt;/code&amp;gt;&lt;br /&gt;
** Something to note about indexing in Python is that the first element is always index 0, and the &#039;&#039;n&#039;&#039;th element is always index &#039;&#039;n&#039;&#039; - 1&lt;br /&gt;
* &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Tuple (immutable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;(1, 3, 5, 7, 9)&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Set (unordered collection of other variables/data types, cannot modify pre-existing elements, but can add new ones)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{3, 7, 9, 5, 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Dictionary/HashMap (unordered mapping of keys to values)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{&#039;b&#039;: 3, &#039;d&#039;: 7, &#039;e&#039;: 9, &#039;c&#039;: 5, &#039;a&#039;: 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variables are assigned with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals) operator. Unlike other programming languages, Python does not require explicit types to be defined when declaring variables; the types are inferred during runtime (as it is an interpreted language). Hence, the only information needed for assignment is the variable name and data to assign. Python variables can have any name, but it must start with a letter or underscore (although the underscore is generally reserved for library variables, so it is best to stick with letters), and can only contain alphanumeric characters and underscores (&amp;lt;code&amp;gt;A-z&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;0-9&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt;). Here are a few examples of variable assignment:&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 long_variable_name = [0, 1, 2, 3, 4]&lt;br /&gt;
 CAPITAL_VARIABLE_NAME = {&#039;apple&#039;, &#039;orange&#039;, &#039;banana&#039;}&lt;br /&gt;
 _starts_with_underscore = {&#039;yes&#039;: 1.0, &#039;no&#039;: 0.0}  # Try to avoid this type of naming if possible!&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
Operators are symbols used to perform mathematical manipulations and operations to data.&lt;br /&gt;
Some of the simplest mathematical operations include:&lt;br /&gt;
&lt;br /&gt;
 # Addition: &lt;br /&gt;
 1 + 2  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Subtraction: &lt;br /&gt;
 2 - 1  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Multiplication: &lt;br /&gt;
 2 * 1  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Division: &lt;br /&gt;
 2 / 1  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
There are other operations that are more complex than these, such as:&lt;br /&gt;
&lt;br /&gt;
 # Exponentiation: &lt;br /&gt;
 2 ** 2  # This will equal 4&lt;br /&gt;
 &lt;br /&gt;
 # Remainder: &lt;br /&gt;
 5 % 4  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Absolute value:&lt;br /&gt;
 abs(-3)  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Square root: &lt;br /&gt;
 sqrt(4)  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Euler&#039;s number:&lt;br /&gt;
 exp(1)  # This will equal e^1&lt;br /&gt;
&lt;br /&gt;
Another useful category of operators are known as assignment operators, which can be used to perform the specified mathematical operation on a variable, and then store the resulting value back into the variable. In order to use assignment operators, you must specify the variable name, followed by the operator symbol with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals sign), and finally the value. For instance, it is possible to add 3 to the value of x and store it in x again like so:&lt;br /&gt;
&lt;br /&gt;
 x = x + 3&lt;br /&gt;
&lt;br /&gt;
However, this statement could be simplified into:&lt;br /&gt;
&lt;br /&gt;
 x += 3&lt;br /&gt;
&lt;br /&gt;
This will be frequently used in physics simulation models, as variables often needed to be updated in this format.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;, you would code:&lt;br /&gt;
 print(&#039;Hello, world!&#039;)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
Another common use case for the print statement is to display a hard-coded string along with a variable. This can be done by casting the variable to a string and &amp;quot;adding&amp;quot; it to the hardcoded string:&lt;br /&gt;
&lt;br /&gt;
 s = &#039;Hello, world #&#039;&lt;br /&gt;
 number = 3&lt;br /&gt;
 print(s + str(number) + &#039;!&#039;)  # Hello, world #3!&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement, followed by a colon. The next line is indented, and then tells that &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement what to do if the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement is &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;. If it is not &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, it moves on to the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement. &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements are only used after &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statements, and cannot be used independently. There can be any number of &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements, but only one &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement. Notice this uses the same syntax as the regular if statement. Lastly, if neither the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; nor the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement(s) are &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, there is an &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement. There can also be only one &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement, though it is not required.&lt;br /&gt;
&lt;br /&gt;
Another important issue regarding &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; and other statements is the code block formatting. Other programming languages tend to use braces for code blocks like this, but in Python it is designated by indentation. This is why it is critical to ensure your program is formatted correctly.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Connectedness==&lt;br /&gt;
As a high-level and syntactically simple language, Python is an excellent choice for the development of complex algorithms. Proficient knowledge of Python is critical to implementing machine learning algorithms, an emerging field that many computer science majors are interested in. Python could be used to efficiently employ these algorithms in industries such as stock market analysis, helping to understand trends in the way assets rise and fall.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
The concept of the Python programming language was developed in the late 1980s. In 1991, Guido van Rossum created the first version of the Python programming language, releasing it with the original intent of code readability (thanks to its use of whitespace and indentation).&lt;br /&gt;
&lt;br /&gt;
In 2000, Python 2 was released which contained several new backwards-incompatible features, such as list comprehension and a garbage collection system.&lt;br /&gt;
&lt;br /&gt;
The first version of Python 3 was released in 2008, while Python 2 was still in use, creating a rift between Python developers on version usage.&lt;br /&gt;
&lt;br /&gt;
Finally, on January 1st, 2020, Python 2 reached its end-of-life date, no longer officially supported by the Python Software Foundation.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [http://www.physicsbook.gatech.edu/VPython VPython] describes the basics of VPython and using it to create 3D models&lt;br /&gt;
* The [http://www.physicsbook.gatech.edu/GlowScript GlowScript] wiki page provides detailed instructions for how to use VPython on the GlowScript website&lt;br /&gt;
&lt;br /&gt;
===Further reading===&lt;br /&gt;
* [https://www.freecodecamp.org/news/what-can-you-do-with-python-the-3-main-applications-518db9a68a78/ What exactly can you do with Python? Here are Python&#039;s 3 main applications]: This article provides several examples of industry applications of Python&lt;br /&gt;
* [https://towardsdatascience.com/how-to-build-your-own-neural-network-from-scratch-in-python-68998a08e4f6 How to build your own Neural Network from scratch in Python] gives a comprehensive guide on applying Python to machine learning&lt;br /&gt;
&lt;br /&gt;
===External links===&lt;br /&gt;
* For a more comprehensive guide with getting Python set up, go to [https://www.python.org/about/gettingstarted/ https://www.python.org/about/gettingstarted/]&lt;br /&gt;
* The [https://pypi.org/ Python Package Index] (PyPI) is a repository of community-created Python software packages that can be easily installed and used with Python code&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38895</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38895"/>
		<updated>2020-11-15T07:52:25Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
Python is an interpreted, high-level programming language. As a general-purpose language, it is used for a variety of applications, which makes it an obvious choice for computational physics models, considering its shallow learning curve and syntactically simplistic features. It is also OS-independent, allowing it to be run on virtually any machine. &lt;br /&gt;
&lt;br /&gt;
===VPython===&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although VPython slightly differs from the actual Python programming language, the majority of functionality remains the same, including all syntax. For the sole purpose of this class, however, it is functionally equivalent to Python, which is why it is imperative to understand the underlying Python language. Most of the labs done this year (which includes any labs requiring the construction of a physics simulation model) will be done using the VPython.&lt;br /&gt;
&lt;br /&gt;
==Downloading/Installation==&lt;br /&gt;
&lt;br /&gt;
===Versions===&lt;br /&gt;
Python has two major versions: Python 2 and 3&lt;br /&gt;
&lt;br /&gt;
However, on January 1st, 2020, version 2.x was officially deprecated and no longer officially supported by the Python Foundation. As a result, the majority of the Python community have already migrated away from the dying version. In any case, Python 2.x has significant syntactical differences that Python 3.x is not backwards-compatible with (hence, the major version change), which is why this course will be attempting to adhere to the guidelines set by Python 3.&lt;br /&gt;
&lt;br /&gt;
===Downloading===&lt;br /&gt;
The latest stable version of Python 3 available is [https://www.python.org/downloads/release/python-390/ 3.9.0] (as of November 2020).&lt;br /&gt;
&lt;br /&gt;
Older versions of Python 3 can be found at [https://www.python.org/downloads/ https://www.python.org/downloads/].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this class, it is not necessary to download and install VPython, as we will be working with VPython through the virtual [https://www.glowscript.org/ GlowScript] environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Downloading==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
Variables in Python are named items/containers that allow data to be stored (only during the execution of the program; after the program finishes, the variables are no longer retained). Python is an Object-Oriented Programming (OOP) language, which essentially means that the variables can be thought of as &amp;quot;objects,&amp;quot; or abstract data types representing various forms of information. For instance, &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; is a variable type that holds only integers (without any fractional values), while &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt; is another variable type that holds decimal values. Below is a list of common variable types in Python:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Integer&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Float (decimal)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3.25&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: String&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: List (modifiable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;[1, 3, 5, 7, 9]&amp;lt;/code&amp;gt;&lt;br /&gt;
** Something to note about indexing in Python is that the first element is always index 0, and the &#039;&#039;n&#039;&#039;th element is always index &#039;&#039;n&#039;&#039; - 1&lt;br /&gt;
* &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Tuple (immutable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;(1, 3, 5, 7, 9)&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Set (unordered collection of other variables/data types, cannot modify pre-existing elements, but can add new ones)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{3, 7, 9, 5, 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Dictionary/HashMap (unordered mapping of keys to values)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{&#039;b&#039;: 3, &#039;d&#039;: 7, &#039;e&#039;: 9, &#039;c&#039;: 5, &#039;a&#039;: 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variables are assigned with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals) operator. Unlike other programming languages, Python does not require explicit types to be defined when declaring variables; the types are inferred during runtime (as it is an interpreted language). Hence, the only information needed for assignment is the variable name and data to assign. Python variables can have any name, but it must start with a letter or underscore (although the underscore is generally reserved for library variables, so it is best to stick with letters), and can only contain alphanumeric characters and underscores (&amp;lt;code&amp;gt;A-z&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;0-9&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt;). Here are a few examples of variable assignment:&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 long_variable_name = [0, 1, 2, 3, 4]&lt;br /&gt;
 CAPITAL_VARIABLE_NAME = {&#039;apple&#039;, &#039;orange&#039;, &#039;banana&#039;}&lt;br /&gt;
 _starts_with_underscore = {&#039;yes&#039;: 1.0, &#039;no&#039;: 0.0}  # Try to avoid this type of naming if possible!&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
Operators are symbols used to perform mathematical manipulations and operations to data.&lt;br /&gt;
Some of the simplest mathematical operations include:&lt;br /&gt;
&lt;br /&gt;
 # Addition: &lt;br /&gt;
 1 + 2  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Subtraction: &lt;br /&gt;
 2 - 1  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Multiplication: &lt;br /&gt;
 2 * 1  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Division: &lt;br /&gt;
 2 / 1  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
There are other operations that are more complex than these, such as:&lt;br /&gt;
&lt;br /&gt;
 # Exponentiation: &lt;br /&gt;
 2 ** 2  # This will equal 4&lt;br /&gt;
 &lt;br /&gt;
 # Remainder: &lt;br /&gt;
 5 % 4  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Absolute value:&lt;br /&gt;
 abs(-3)  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Square root: &lt;br /&gt;
 sqrt(4)  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Euler&#039;s number:&lt;br /&gt;
 exp(1)  # This will equal e^1&lt;br /&gt;
&lt;br /&gt;
Another useful category of operators are known as assignment operators, which can be used to perform the specified mathematical operation on a variable, and then store the resulting value back into the variable. In order to use assignment operators, you must specify the variable name, followed by the operator symbol with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals sign), and finally the value. For instance, it is possible to add 3 to the value of x and store it in x again like so:&lt;br /&gt;
&lt;br /&gt;
 x = x + 3&lt;br /&gt;
&lt;br /&gt;
However, this statement could be simplified into:&lt;br /&gt;
&lt;br /&gt;
 x += 3&lt;br /&gt;
&lt;br /&gt;
This will be frequently used in physics simulation models, as variables often needed to be updated in this format.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;, you would code:&lt;br /&gt;
 print(&#039;Hello, world!&#039;)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
Another common use case for the print statement is to display a hard-coded string along with a variable. This can be done by casting the variable to a string and &amp;quot;adding&amp;quot; it to the hardcoded string:&lt;br /&gt;
&lt;br /&gt;
 s = &#039;Hello, world #&#039;&lt;br /&gt;
 number = 3&lt;br /&gt;
 print(s + str(number) + &#039;!&#039;)  # Hello, world #3!&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement, followed by a colon. The next line is indented, and then tells that &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement what to do if the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement is &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;. If it is not &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, it moves on to the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement. &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements are only used after &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statements, and cannot be used independently. There can be any number of &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements, but only one &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement. Notice this uses the same syntax as the regular if statement. Lastly, if neither the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; nor the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement(s) are &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, there is an &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement. There can also be only one &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement, though it is not required.&lt;br /&gt;
&lt;br /&gt;
Another important issue regarding &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; and other statements is the code block formatting. Other programming languages tend to use braces for code blocks like this, but in Python it is designated by indentation. This is why it is critical to ensure your program is formatted correctly.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Connectedness==&lt;br /&gt;
As a high-level and syntactically simple language, Python is an excellent choice for the development of complex algorithms. Proficient knowledge of Python is critical to implementing machine learning algorithms, an emerging field that many computer science majors are interested in. Python could be used to efficiently employ these algorithms in industries such as stock market analysis, helping to understand trends in the way assets rise and fall.&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38892</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38892"/>
		<updated>2020-11-15T01:15:08Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
Python is an interpreted, high-level programming language. As a general-purpose language, it is used for a variety of applications, which makes it an obvious choice for computational physics models, considering its shallow learning curve and syntactically simplistic features. It is also OS-independent, allowing it to be run on virtually any machine. &lt;br /&gt;
&lt;br /&gt;
===VPython===&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although VPython slightly differs from the actual Python programming language, the majority of functionality remains the same, including all syntax. For the sole purpose of this class, however, it is functionally equivalent to Python, which is why it is imperative to understand the underlying Python language. Most of the labs done this year (which includes any labs requiring the construction of a physics simulation model) will be done using the VPython.&lt;br /&gt;
&lt;br /&gt;
==Downloading/Installation==&lt;br /&gt;
&lt;br /&gt;
===Versions===&lt;br /&gt;
Python has two major versions: Python 2 and 3&lt;br /&gt;
&lt;br /&gt;
However, on January 1st, 2020, version 2.x was officially deprecated and no longer officially supported by the Python Foundation. As a result, the majority of the Python community have already migrated away from the dying version. In any case, Python 2.x has significant syntactical differences that Python 3.x is not backwards-compatible with (hence, the major version change), which is why this course will be attempting to adhere to the guidelines set by Python 3.&lt;br /&gt;
&lt;br /&gt;
===Downloading===&lt;br /&gt;
The latest stable version of Python 3 available is [https://www.python.org/downloads/release/python-390/ 3.9.0] (as of November 2020).&lt;br /&gt;
&lt;br /&gt;
Older versions of Python 3 can be found at [https://www.python.org/downloads/ https://www.python.org/downloads/].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this class, it is not necessary to download and install VPython, as we will be working with VPython through the virtual [https://www.glowscript.org/ GlowScript] environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Downloading==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
Variables in Python are named items/containers that allow data to be stored (only during the execution of the program; after the program finishes, the variables are no longer retained). Python is an Object-Oriented Programming (OOP) language, which essentially means that the variables can be thought of as &amp;quot;objects,&amp;quot; or abstract data types representing various forms of information. For instance, &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; is a variable type that holds only integers (without any fractional values), while &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt; is another variable type that holds decimal values. Below is a list of common variable types in Python:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Integer&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Float (decimal)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3.25&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: String&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: List (modifiable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;[1, 3, 5, 7, 9]&amp;lt;/code&amp;gt;&lt;br /&gt;
** Something to note about indexing in Python is that the first element is always index 0, and the &#039;&#039;n&#039;&#039;th element is always index &#039;&#039;n&#039;&#039; - 1&lt;br /&gt;
* &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Tuple (immutable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;(1, 3, 5, 7, 9)&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Set (unordered collection of other variables/data types, cannot modify pre-existing elements, but can add new ones)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{3, 7, 9, 5, 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Dictionary/HashMap (unordered mapping of keys to values)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{&#039;b&#039;: 3, &#039;d&#039;: 7, &#039;e&#039;: 9, &#039;c&#039;: 5, &#039;a&#039;: 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variables are assigned with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals) operator. Unlike other programming languages, Python does not require explicit types to be defined when declaring variables; the types are inferred during runtime (as it is an interpreted language). Hence, the only information needed for assignment is the variable name and data to assign. Python variables can have any name, but it must start with a letter or underscore (although the underscore is generally reserved for library variables, so it is best to stick with letters), and can only contain alphanumeric characters and underscores (&amp;lt;code&amp;gt;A-z&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;0-9&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt;). Here are a few examples of variable assignment:&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 long_variable_name = [0, 1, 2, 3, 4]&lt;br /&gt;
 CAPITAL_VARIABLE_NAME = {&#039;apple&#039;, &#039;orange&#039;, &#039;banana&#039;}&lt;br /&gt;
 _starts_with_underscore = {&#039;yes&#039;: 1.0, &#039;no&#039;: 0.0}  # Try to avoid this type of naming if possible!&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
Operators are symbols used to perform mathematical manipulations and operations to data.&lt;br /&gt;
Some of the simplest mathematical operations include:&lt;br /&gt;
&lt;br /&gt;
 # Addition: &lt;br /&gt;
 1 + 2  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Subtraction: &lt;br /&gt;
 2 - 1  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Multiplication: &lt;br /&gt;
 2 * 1  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Division: &lt;br /&gt;
 2 / 1  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
There are other operations that are more complex than these, such as:&lt;br /&gt;
&lt;br /&gt;
 # Exponentiation: &lt;br /&gt;
 2 ** 2  # This will equal 4&lt;br /&gt;
 &lt;br /&gt;
 # Remainder: &lt;br /&gt;
 5 % 4  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Absolute value:&lt;br /&gt;
 abs(-3)  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Square root: &lt;br /&gt;
 sqrt(4)  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Euler&#039;s number:&lt;br /&gt;
 exp(1)  # This will equal e^1&lt;br /&gt;
&lt;br /&gt;
Another useful category of operators are known as assignment operators, which can be used to perform the specified mathematical operation on a variable, and then store the resulting value back into the variable. In order to use assignment operators, you must specify the variable name, followed by the operator symbol with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals sign), and finally the value. For instance, it is possible to add 3 to the value of x and store it in x again like so:&lt;br /&gt;
&lt;br /&gt;
 x = x + 3&lt;br /&gt;
&lt;br /&gt;
However, this statement could be simplified into:&lt;br /&gt;
&lt;br /&gt;
 x += 3&lt;br /&gt;
&lt;br /&gt;
This will be frequently used in physics simulation models, as variables often needed to be updated in this format.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;, you would code:&lt;br /&gt;
 print(&#039;Hello, world!&#039;)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
Another common use case for the print statement is to display a hard-coded string along with a variable. This can be done by casting the variable to a string and &amp;quot;adding&amp;quot; it to the hardcoded string:&lt;br /&gt;
&lt;br /&gt;
 s = &#039;Hello, world #&#039;&lt;br /&gt;
 number = 3&lt;br /&gt;
 print(s + str(number) + &#039;!&#039;)  # Hello, world #3!&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement, followed by a colon. The next line is indented, and then tells that &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement what to do if the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement is &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;. If it is not &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, it moves on to the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement. &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements are only used after &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statements, and cannot be used independently. There can be any number of &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements, but only one &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement. Notice this uses the same syntax as the regular if statement. Lastly, if neither the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; nor the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement(s) are &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, there is an &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement. There can also be only one &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement, though it is not required.&lt;br /&gt;
&lt;br /&gt;
Another important issue regarding &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; and other statements is the code block formatting. Other programming languages tend to use braces for code blocks like this, but in Python it is designated by indentation. This is why it is critical to ensure your program is formatted correctly.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38891</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38891"/>
		<updated>2020-11-15T01:11:57Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: Conditionals and print statement update&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
Python is an interpreted, high-level programming language. As a general-purpose language, it is used for a variety of applications, which makes it an obvious choice for computational physics models, considering its shallow learning curve and syntactically simplistic features. It is also OS-independent, allowing it to be run on virtually any machine. &lt;br /&gt;
&lt;br /&gt;
===VPython===&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although VPython slightly differs from the actual Python programming language, the majority of functionality remains the same, including all syntax. For the sole purpose of this class, however, it is functionally equivalent to Python, which is why it is imperative to understand the underlying Python language. Most of the labs done this year (which includes any labs requiring the construction of a physics simulation model) will be done using the VPython.&lt;br /&gt;
&lt;br /&gt;
==Downloading/Installation==&lt;br /&gt;
&lt;br /&gt;
===Versions===&lt;br /&gt;
Python has two major versions: Python 2 and 3&lt;br /&gt;
&lt;br /&gt;
However, on January 1st, 2020, version 2.x was officially deprecated and no longer officially supported by the Python Foundation. As a result, the majority of the Python community have already migrated away from the dying version. In any case, Python 2.x has significant syntactical differences that Python 3.x is not backwards-compatible with (hence, the major version change), which is why this course will be attempting to adhere to the guidelines set by Python 3.&lt;br /&gt;
&lt;br /&gt;
===Downloading===&lt;br /&gt;
The latest stable version of Python 3 available is [https://www.python.org/downloads/release/python-390/ 3.9.0] (as of November 2020).&lt;br /&gt;
&lt;br /&gt;
Older versions of Python 3 can be found at [https://www.python.org/downloads/ https://www.python.org/downloads/].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this class, it is not necessary to download and install VPython, as we will be working with VPython through the virtual [https://www.glowscript.org/ GlowScript] environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Downloading==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
Variables in Python are named items/containers that allow data to be stored (only during the execution of the program; after the program finishes, the variables are no longer retained). Python is an Object-Oriented Programming (OOP) language, which essentially means that the variables can be thought of as &amp;quot;objects,&amp;quot; or abstract data types representing various forms of information. For instance, &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; is a variable type that holds only integers (without any fractional values), while &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt; is another variable type that holds decimal values. Below is a list of common variable types in Python:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Integer&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Float (decimal)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3.25&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: String&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: List (modifiable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;[1, 3, 5, 7, 9]&amp;lt;/code&amp;gt;&lt;br /&gt;
** Something to note about indexing in Python is that the first element is always index 0, and the &#039;&#039;n&#039;&#039;th element is always index &#039;&#039;n&#039;&#039; - 1&lt;br /&gt;
* &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Tuple (immutable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;(1, 3, 5, 7, 9)&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Set (unordered collection of other variables/data types, cannot modify pre-existing elements, but can add new ones)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{3, 7, 9, 5, 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Dictionary/HashMap (unordered mapping of keys to values)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{&#039;b&#039;: 3, &#039;d&#039;: 7, &#039;e&#039;: 9, &#039;c&#039;: 5, &#039;a&#039;: 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variables are assigned with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals) operator. Unlike other programming languages, Python does not require explicit types to be defined when declaring variables; the types are inferred during runtime (as it is an interpreted language). Hence, the only information needed for assignment is the variable name and data to assign. Python variables can have any name, but it must start with a letter or underscore (although the underscore is generally reserved for library variables, so it is best to stick with letters), and can only contain alphanumeric characters and underscores (&amp;lt;code&amp;gt;A-z&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;0-9&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt;). Here are a few examples of variable assignment:&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 long_variable_name = [0, 1, 2, 3, 4]&lt;br /&gt;
 CAPITAL_VARIABLE_NAME = {&#039;apple&#039;, &#039;orange&#039;, &#039;banana&#039;}&lt;br /&gt;
 _starts_with_underscore = {&#039;yes&#039;: 1.0, &#039;no&#039;: 0.0}  # Try to avoid this type of naming if possible!&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
Operators are symbols used to perform mathematical manipulations and operations to data.&lt;br /&gt;
Some of the simplest mathematical operations include:&lt;br /&gt;
&lt;br /&gt;
 # Addition: &lt;br /&gt;
 1 + 2  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Subtraction: &lt;br /&gt;
 2 - 1  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Multiplication: &lt;br /&gt;
 2 * 1  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Division: &lt;br /&gt;
 2 / 1  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
There are other operations that are more complex than these, such as:&lt;br /&gt;
&lt;br /&gt;
 # Exponentiation: &lt;br /&gt;
 2 ** 2  # This will equal 4&lt;br /&gt;
 &lt;br /&gt;
 # Remainder: &lt;br /&gt;
 5 % 4  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Absolute value:&lt;br /&gt;
 abs(-3)  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Square root: &lt;br /&gt;
 sqrt(4)  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
Another useful category of operators are known as assignment operators, which can be used to perform the specified mathematical operation on a variable, and then store the resulting value back into the variable. In order to use assignment operators, you must specify the variable name, followed by the operator symbol with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals sign), and finally the value. For instance, it is possible to add 3 to the value of x and store it in x again like so:&lt;br /&gt;
&lt;br /&gt;
 x = x + 3&lt;br /&gt;
&lt;br /&gt;
However, this statement could be simplified into:&lt;br /&gt;
&lt;br /&gt;
 x += 3&lt;br /&gt;
&lt;br /&gt;
This will be frequently used in physics simulation models, as variables often needed to be updated in this format.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical &amp;lt;code&amp;gt;&#039;Hello, world!&#039;&amp;lt;/code&amp;gt;, you would code:&lt;br /&gt;
 print(&#039;Hello, world!&#039;)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
Another common use case for the print statement is to display a hard-coded string along with a variable. This can be done by casting the variable to a string and &amp;quot;adding&amp;quot; it to the hardcoded string:&lt;br /&gt;
&lt;br /&gt;
 s = &#039;Hello, world #&#039;&lt;br /&gt;
 number = 3&lt;br /&gt;
 print(s + str(number) + &#039;!&#039;)  # Hello, world #3!&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement, followed by a colon. The next line is indented, and then tells that &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement what to do if the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement is &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;. If it is not &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, it moves on to the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement. &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements are only used after &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statements, and cannot be used independently. There can be any number of &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statements, but only one &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; statement. Notice this uses the same syntax as the regular if statement. Lastly, if neither the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; nor the &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt; statement(s) are &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;, there is an &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement. There can also be only one &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; statement, though it is not required.&lt;br /&gt;
&lt;br /&gt;
Another important issue regarding &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt; and other statements is the code block formatting. Other programming languages tend to use braces for code blocks like this, but in Python it is designated by indentation. This is why it is critical to ensure your program is formatted correctly.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38890</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38890"/>
		<updated>2020-11-14T23:28:14Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
Python is an interpreted, high-level programming language. As a general-purpose language, it is used for a variety of applications, which makes it an obvious choice for computational physics models, considering its shallow learning curve and syntactically simplistic features. It is also OS-independent, allowing it to be run on virtually any machine. &lt;br /&gt;
&lt;br /&gt;
===VPython===&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although VPython slightly differs from the actual Python programming language, the majority of functionality remains the same, including all syntax. For the sole purpose of this class, however, it is functionally equivalent to Python, which is why it is imperative to understand the underlying Python language. Most of the labs done this year (which includes any labs requiring the construction of a physics simulation model) will be done using the VPython.&lt;br /&gt;
&lt;br /&gt;
==Downloading/Installation==&lt;br /&gt;
&lt;br /&gt;
===Versions===&lt;br /&gt;
Python has two major versions: Python 2 and 3&lt;br /&gt;
&lt;br /&gt;
However, on January 1st, 2020, version 2.x was officially deprecated and no longer officially supported by the Python Foundation. As a result, the majority of the Python community have already migrated away from the dying version. In any case, Python 2.x has significant syntactical differences that Python 3.x is not backwards-compatible with (hence, the major version change), which is why this course will be attempting to adhere to the guidelines set by Python 3.&lt;br /&gt;
&lt;br /&gt;
===Downloading===&lt;br /&gt;
The latest stable version of Python 3 available is [https://www.python.org/downloads/release/python-390/ 3.9.0] (as of November 2020).&lt;br /&gt;
&lt;br /&gt;
Older versions of Python 3 can be found at [https://www.python.org/downloads/ https://www.python.org/downloads/].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this class, it is not necessary to download and install VPython, as we will be working with VPython through the virtual [https://www.glowscript.org/ GlowScript] environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Downloading==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
Variables in Python are named items/containers that allow data to be stored (only during the execution of the program; after the program finishes, the variables are no longer retained). Python is an Object-Oriented Programming (OOP) language, which essentially means that the variables can be thought of as &amp;quot;objects,&amp;quot; or abstract data types representing various forms of information. For instance, &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; is a variable type that holds only integers (without any fractional values), while &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt; is another variable type that holds decimal values. Below is a list of common variable types in Python:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Integer&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Float (decimal)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3.25&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: String&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;&#039;Hello, World!&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: List (modifiable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;[1, 3, 5, 7, 9]&amp;lt;/code&amp;gt;&lt;br /&gt;
** Something to note about indexing in Python is that the first element is always index 0, and the &#039;&#039;n&#039;&#039;th element is always index &#039;&#039;n&#039;&#039; - 1&lt;br /&gt;
* &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Tuple (immutable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;(1, 3, 5, 7, 9)&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Set (unordered collection of other variables/data types, cannot modify pre-existing elements, but can add new ones)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{3, 7, 9, 5, 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Dictionary/HashMap (unordered mapping of keys to values)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{&#039;b&#039;: 3, &#039;d&#039;: 7, &#039;e&#039;: 9, &#039;c&#039;: 5, &#039;a&#039;: 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variables are assigned with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals) operator. Unlike other programming languages, Python does not require explicit types to be defined when declaring variables; the types are inferred during runtime (as it is an interpreted language). Hence, the only information needed for assignment is the variable name and data to assign. Python variables can have any name, but it must start with a letter or underscore (although the underscore is generally reserved for library variables, so it is best to stick with letters), and can only contain alphanumeric characters and underscores (&amp;lt;code&amp;gt;A-z&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;0-9&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt;). Here are a few examples of variable assignment:&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 long_variable_name = [0, 1, 2, 3, 4]&lt;br /&gt;
 CAPITAL_VARIABLE_NAME = {&#039;apple&#039;, &#039;orange&#039;, &#039;banana&#039;}&lt;br /&gt;
 _starts_with_underscore = {&#039;yes&#039;: 1.0, &#039;no&#039;: 0.0}  # Try to avoid this type of naming if possible!&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
Operators are symbols used to perform mathematical manipulations and operations to data.&lt;br /&gt;
Some of the simplest mathematical operations include:&lt;br /&gt;
&lt;br /&gt;
 # Addition: &lt;br /&gt;
 1 + 2  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Subtraction: &lt;br /&gt;
 2 - 1  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Multiplication: &lt;br /&gt;
 2 * 1  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Division: &lt;br /&gt;
 2 / 1  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
There are other operations that are more complex than these, such as:&lt;br /&gt;
&lt;br /&gt;
 # Exponentiation: &lt;br /&gt;
 2 ** 2  # This will equal 4&lt;br /&gt;
 &lt;br /&gt;
 # Remainder: &lt;br /&gt;
 5 % 4  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Absolute value:&lt;br /&gt;
 abs(-3)  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Square root: &lt;br /&gt;
 sqrt(4)  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
Another useful category of operators are known as assignment operators, which can be used to perform the specified mathematical operation on a variable, and then store the resulting value back into the variable. In order to use assignment operators, you must specify the variable name, followed by the operator symbol with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals sign), and finally the value. For instance, it is possible to add 3 to the value of x and store it in x again like so:&lt;br /&gt;
&lt;br /&gt;
 x = x + 3&lt;br /&gt;
&lt;br /&gt;
However, this statement could be simplified into:&lt;br /&gt;
&lt;br /&gt;
 x += 3&lt;br /&gt;
&lt;br /&gt;
This will be frequently used in physics simulation models, as variables often needed to be updated in this format.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical “Hello, world!”, you would code:&lt;br /&gt;
 print(“Hello, world!”)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an if statement, followed by a colon. The next line is indented, and then tells that if statement what to do if the if statement is true. If it is not true, it moves on to the elif statement. Elif statements are used after if statements, but when there is still an if statement involved. There can be endless elif statements. Notice this uses the same syntax as the regular if statement. Lastly, if neither the if nor the elif statement(s) are true, there is an else statement. This will print if nothing above was true.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38889</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38889"/>
		<updated>2020-11-14T23:26:46Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
Python is an interpreted, high-level programming language. As a general-purpose language, it is used for a variety of applications, which makes it an obvious choice for computational physics models, considering its shallow learning curve and syntactically simplistic features. It is also OS-independent, allowing it to be run on virtually any machine. &lt;br /&gt;
&lt;br /&gt;
===VPython===&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although VPython slightly differs from the actual Python programming language, the majority of functionality remains the same, including all syntax. For the sole purpose of this class, however, it is functionally equivalent to Python, which is why it is imperative to understand the underlying Python language. Most of the labs done this year (which includes any labs requiring the construction of a physics simulation model) will be done using the VPython.&lt;br /&gt;
&lt;br /&gt;
==Downloading/Installation==&lt;br /&gt;
&lt;br /&gt;
===Versions===&lt;br /&gt;
Python has two major versions: Python 2 and 3&lt;br /&gt;
&lt;br /&gt;
However, on January 1st, 2020, version 2.x was officially deprecated and no longer officially supported by the Python Foundation. As a result, the majority of the Python community have already migrated away from the dying version. In any case, Python 2.x has significant syntactical differences that Python 3.x is not backwards-compatible with (hence, the major version change), which is why this course will be attempting to adhere to the guidelines set by Python 3.&lt;br /&gt;
&lt;br /&gt;
===Downloading===&lt;br /&gt;
The latest stable version of Python 3 available is [https://www.python.org/downloads/release/python-390/ 3.9.0] (as of November 2020).&lt;br /&gt;
&lt;br /&gt;
Older versions of Python 3 can be found at [https://www.python.org/downloads/ https://www.python.org/downloads/].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this class, it is not necessary to download and install VPython, as we will be working with VPython through the virtual [https://www.glowscript.org/ GlowScript] environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Downloading==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
Variables in Python are named items/containers that allow data to be stored (only during the execution of the program; after the program finishes, the variables are no longer retained). Python is an Object-Oriented Programming (OOP) language, which essentially means that the variables can be thought of as &amp;quot;objects,&amp;quot; or abstract data types representing various forms of information. For instance, &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; is a variable type that holds only integers (without any fractional values), while &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt; is another variable type that holds decimal values. Below is a list of common variable types in Python:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Integer&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Float (decimal)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3.25&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: String&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;&#039;Hello, World!&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: List (modifiable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;[1, 3, 5, 7, 9]&amp;lt;/code&amp;gt;&lt;br /&gt;
** Something to note about indexing in Python is that the first element is always index 0, and the &#039;&#039;n&#039;&#039;th element is always index &#039;&#039;n&#039;&#039; - 1&lt;br /&gt;
* &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Tuple (immutable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;(1, 3, 5, 7, 9)&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Set (unordered collection of other variables/data types, cannot modify pre-existing elements, but can add new ones)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{3, 7, 9, 5, 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Dictionary/HashMap (unordered mapping of keys to values)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{&#039;b&#039;: 3, &#039;d&#039;: 7, &#039;e&#039;: 9, &#039;c&#039;: 5, &#039;a&#039;: 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variables are assigned with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals) operator. Unlike other programming languages, Python does not require explicit types to be defined when declaring variables; the types are inferred during runtime (as it is an interpreted language). Hence, the only information needed for assignment is the variable name and data to assign. Python variables can have any name, but it must start with a letter or underscore (although the underscore is generally reserved for library variables, so it is best to stick with letters), and can only contain alphanumeric characters and underscores (&amp;lt;code&amp;gt;A-z&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;0-9&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt;). Here are a few examples of variable assignment:&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 long_variable_name = [0, 1, 2, 3, 4]&lt;br /&gt;
 CAPITAL_VARIABLE_NAME = {&#039;apple&#039;, &#039;orange&#039;, &#039;banana&#039;}&lt;br /&gt;
 _starts_with_underscore = {&#039;yes&#039;: 1.0, &#039;no&#039;: 0.0}  # Try to avoid this type of naming if possible!&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
Operators are symbols used to perform mathematical manipulations and operations to data.&lt;br /&gt;
Some of the simplest mathematical operations include:&lt;br /&gt;
&lt;br /&gt;
 # Addition: &lt;br /&gt;
 1 + 2  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Subtraction: &lt;br /&gt;
 2 - 1  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Multiplication: &lt;br /&gt;
 2 * 1  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Division: &lt;br /&gt;
 2 / 1  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
There are other operations that are more complex than these, such as:&lt;br /&gt;
&lt;br /&gt;
 # Exponentiation: &lt;br /&gt;
 2 ** 2  # This will equal 4&lt;br /&gt;
 &lt;br /&gt;
 # Remainder: &lt;br /&gt;
 5 % 4  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Absolute value:&lt;br /&gt;
 abs(-3)  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Square root: &lt;br /&gt;
 sqrt(4)  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
Another useful category of operators are known as assignment operators, which can be used to perform the specified mathematical operation on a variable, and then store the resulting value back into the variable. In order to use assignment operators, you must specify the variable name, followed by the operator symbol with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals sign), and finally the value. For instance, I can add 3 to the value of x and store it in x again like so:&lt;br /&gt;
&lt;br /&gt;
 x = x + 3&lt;br /&gt;
&lt;br /&gt;
However, I could shorten this to just:&lt;br /&gt;
&lt;br /&gt;
 x += 3&lt;br /&gt;
&lt;br /&gt;
This will be frequently used in physics simulation models, as variables often needed to be updated in this format.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical “Hello, world!”, you would code:&lt;br /&gt;
 print(“Hello, world!”)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an if statement, followed by a colon. The next line is indented, and then tells that if statement what to do if the if statement is true. If it is not true, it moves on to the elif statement. Elif statements are used after if statements, but when there is still an if statement involved. There can be endless elif statements. Notice this uses the same syntax as the regular if statement. Lastly, if neither the if nor the elif statement(s) are true, there is an else statement. This will print if nothing above was true.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38888</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38888"/>
		<updated>2020-11-14T23:26:18Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: Updated operators section, added discussion on assignment operators&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
Python is an interpreted, high-level programming language. As a general-purpose language, it is used for a variety of applications, which makes it an obvious choice for computational physics models, considering its shallow learning curve and syntactically simplistic features. It is also OS-independent, allowing it to be run on virtually any machine. &lt;br /&gt;
&lt;br /&gt;
===VPython===&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although VPython slightly differs from the actual Python programming language, the majority of functionality remains the same, including all syntax. For the sole purpose of this class, however, it is functionally equivalent to Python, which is why it is imperative to understand the underlying Python language. Most of the labs done this year (which includes any labs requiring the construction of a physics simulation model) will be done using the VPython.&lt;br /&gt;
&lt;br /&gt;
==Downloading/Installation==&lt;br /&gt;
&lt;br /&gt;
===Versions===&lt;br /&gt;
Python has two major versions: Python 2 and 3&lt;br /&gt;
&lt;br /&gt;
However, on January 1st, 2020, version 2.x was officially deprecated and no longer officially supported by the Python Foundation. As a result, the majority of the Python community have already migrated away from the dying version. In any case, Python 2.x has significant syntactical differences that Python 3.x is not backwards-compatible with (hence, the major version change), which is why this course will be attempting to adhere to the guidelines set by Python 3.&lt;br /&gt;
&lt;br /&gt;
===Downloading===&lt;br /&gt;
The latest stable version of Python 3 available is [https://www.python.org/downloads/release/python-390/ 3.9.0] (as of November 2020).&lt;br /&gt;
&lt;br /&gt;
Older versions of Python 3 can be found at [https://www.python.org/downloads/ https://www.python.org/downloads/].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this class, it is not necessary to download and install VPython, as we will be working with VPython through the virtual [https://www.glowscript.org/ GlowScript] environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Downloading==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
Variables in Python are named items/containers that allow data to be stored (only during the execution of the program; after the program finishes, the variables are no longer retained). Python is an Object-Oriented Programming (OOP) language, which essentially means that the variables can be thought of as &amp;quot;objects,&amp;quot; or abstract data types representing various forms of information. For instance, &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; is a variable type that holds only integers (without any fractional values), while &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt; is another variable type that holds decimal values. Below is a list of common variable types in Python:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Integer&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Float (decimal)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3.25&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: String&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;&#039;Hello, World!&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: List (modifiable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;[1, 3, 5, 7, 9]&amp;lt;/code&amp;gt;&lt;br /&gt;
** Something to note about indexing in Python is that the first element is always index 0, and the &#039;&#039;n&#039;&#039;th element is always index &#039;&#039;n&#039;&#039; - 1&lt;br /&gt;
* &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Tuple (immutable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;(1, 3, 5, 7, 9)&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Set (unordered collection of other variables/data types, cannot modify pre-existing elements, but can add new ones)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{3, 7, 9, 5, 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Dictionary/HashMap (unordered mapping of keys to values)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{&#039;b&#039;: 3, &#039;d&#039;: 7, &#039;e&#039;: 9, &#039;c&#039;: 5, &#039;a&#039;: 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variables are assigned with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals) operator. Unlike other programming languages, Python does not require explicit types to be defined when declaring variables; the types are inferred during runtime (as it is an interpreted language). Hence, the only information needed for assignment is the variable name and data to assign. Python variables can have any name, but it must start with a letter or underscore (although the underscore is generally reserved for library variables, so it is best to stick with letters), and can only contain alphanumeric characters and underscores (&amp;lt;code&amp;gt;A-z&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;0-9&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt;). Here are a few examples of variable assignment:&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 long_variable_name = [0, 1, 2, 3, 4]&lt;br /&gt;
 CAPITAL_VARIABLE_NAME = {&#039;apple&#039;, &#039;orange&#039;, &#039;banana&#039;}&lt;br /&gt;
 _starts_with_underscore = {&#039;yes&#039;: 1.0, &#039;no&#039;: 0.0}  # Try to avoid this type of naming if possible!&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
Operators are symbols used to perform mathematical manipulations and operations to data.&lt;br /&gt;
Some of the simplest mathematical operations include:&lt;br /&gt;
&lt;br /&gt;
 # Addition: &lt;br /&gt;
 1 + 2  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Subtraction: &lt;br /&gt;
 2 - 1  # This will equal 1&lt;br /&gt;
 &lt;br /&gt;
 # Multiplication: &lt;br /&gt;
 2 * 1  # This will equal 2&lt;br /&gt;
 &lt;br /&gt;
 # Division: &lt;br /&gt;
 2 / 1  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
There are other operations that are more complex than these, such as:&lt;br /&gt;
&lt;br /&gt;
 # Exponentiation: &lt;br /&gt;
 2 ** 2  # This will equal 4&lt;br /&gt;
 &lt;br /&gt;
 # Remainder: &lt;br /&gt;
 5 % 4  # This will equal 1&lt;br /&gt;
&lt;br /&gt;
 # Absolute value:&lt;br /&gt;
 abs(-3)  # This will equal 3&lt;br /&gt;
 &lt;br /&gt;
 # Square root: &lt;br /&gt;
 sqrt(4)  # This will equal 2&lt;br /&gt;
&lt;br /&gt;
Another useful category of operators are known as assignment operators, which can be used to perform the specified mathematical operation on a variable, and then store the resulting value back into the variable. In order to use assignment operators, you must specify the variable name, followed by the operator symbol with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals sign), and finally the value. For instance, I can add 3 to the value of x and store it in x again like so:&lt;br /&gt;
&lt;br /&gt;
 x = x + 3&lt;br /&gt;
&lt;br /&gt;
However, I could shorten this to just:&lt;br /&gt;
&lt;br /&gt;
 x += 3&lt;br /&gt;
&lt;br /&gt;
This will be frequently used in physics simulation models, as variables often needed to be updated in this format.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical “Hello, world!”, you would code:&lt;br /&gt;
 print(“Hello, world!”)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an if statement, followed by a colon. The next line is indented, and then tells that if statement what to do if the if statement is true. If it is not true, it moves on to the elif statement. Elif statements are used after if statements, but when there is still an if statement involved. There can be endless elif statements. Notice this uses the same syntax as the regular if statement. Lastly, if neither the if nor the elif statement(s) are true, there is an else statement. This will print if nothing above was true.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38887</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38887"/>
		<updated>2020-11-14T23:08:55Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: Added new information to variables section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
Python is an interpreted, high-level programming language. As a general-purpose language, it is used for a variety of applications, which makes it an obvious choice for computational physics models, considering its shallow learning curve and syntactically simplistic features. It is also OS-independent, allowing it to be run on virtually any machine. &lt;br /&gt;
&lt;br /&gt;
===VPython===&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although VPython slightly differs from the actual Python programming language, the majority of functionality remains the same, including all syntax. For the sole purpose of this class, however, it is functionally equivalent to Python, which is why it is imperative to understand the underlying Python language. Most of the labs done this year (which includes any labs requiring the construction of a physics simulation model) will be done using the VPython.&lt;br /&gt;
&lt;br /&gt;
==Downloading/Installation==&lt;br /&gt;
&lt;br /&gt;
===Versions===&lt;br /&gt;
Python has two major versions: Python 2 and 3&lt;br /&gt;
&lt;br /&gt;
However, on January 1st, 2020, version 2.x was officially deprecated and no longer officially supported by the Python Foundation. As a result, the majority of the Python community have already migrated away from the dying version. In any case, Python 2.x has significant syntactical differences that Python 3.x is not backwards-compatible with (hence, the major version change), which is why this course will be attempting to adhere to the guidelines set by Python 3.&lt;br /&gt;
&lt;br /&gt;
===Downloading===&lt;br /&gt;
The latest stable version of Python 3 available is [https://www.python.org/downloads/release/python-390/ 3.9.0] (as of November 2020).&lt;br /&gt;
&lt;br /&gt;
Older versions of Python 3 can be found at [https://www.python.org/downloads/ https://www.python.org/downloads/].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this class, it is not necessary to download and install VPython, as we will be working with VPython through the virtual [https://www.glowscript.org/ GlowScript] environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Downloading==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
Variables in Python are named items/containers that allow data to be stored (only during the execution of the program; after the program finishes, the variables are no longer retained). Python is an Object-Oriented Programming (OOP) language, which essentially means that the variables can be thought of as &amp;quot;objects,&amp;quot; or abstract data types representing various forms of information. For instance, &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; is a variable type that holds only integers (without any fractional values), while &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt; is another variable type that holds decimal values. Below is a list of common variable types in Python:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Integer&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Float (decimal)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;3.25&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: String&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;&#039;Hello, World!&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: List (modifiable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;[1, 3, 5, 7, 9]&amp;lt;/code&amp;gt;&lt;br /&gt;
** Something to note about indexing in Python is that the first element is always index 0, and the &#039;&#039;n&#039;&#039;th element is always index &#039;&#039;n&#039;&#039; - 1&lt;br /&gt;
* &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Tuple (immutable array, ordered collection of other variables/data types)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;(1, 3, 5, 7, 9)&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Set (unordered collection of other variables/data types, cannot modify pre-existing elements, but can add new ones)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{3, 7, 9, 5, 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;&lt;br /&gt;
** Type: Dictionary/HashMap (unordered mapping of keys to values)&lt;br /&gt;
** Example: &amp;lt;code&amp;gt;{&#039;b&#039;: 3, &#039;d&#039;: 7, &#039;e&#039;: 9, &#039;c&#039;: 5, &#039;a&#039;: 1}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Variables are assigned with an &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; (equals) operator. Unlike other programming languages, Python does not require explicit types to be defined when declaring variables; the types are inferred during runtime (as it is an interpreted language). Hence, the only information needed for assignment is the variable name and data to assign. Python variables can have any name, but it must start with a letter or underscore (although the underscore is generally reserved for library variables, so it is best to stick with letters), and can only contain alphanumeric characters and underscores (&amp;lt;code&amp;gt;A-z&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;0-9&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt;). Here are a few examples of variable assignment:&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 long_variable_name = [0, 1, 2, 3, 4]&lt;br /&gt;
 CAPITAL_VARIABLE_NAME = {&#039;apple&#039;, &#039;orange&#039;, &#039;banana&#039;}&lt;br /&gt;
 _starts_with_underscore = {&#039;yes&#039;: 1.0, &#039;no&#039;: 0.0}  # Try to avoid this type of naming if possible!&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
&lt;br /&gt;
===Assignment===&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Math Operations==&lt;br /&gt;
&lt;br /&gt;
Math operations are simple in Python. The simple operations, as you might expect, are as follows:&lt;br /&gt;
 #Addition: &lt;br /&gt;
 1+2 #This will equal 3.&lt;br /&gt;
 &lt;br /&gt;
 #Subtraction: &lt;br /&gt;
 2-1 #This will equal 1.&lt;br /&gt;
 &lt;br /&gt;
 #Multiplication: &lt;br /&gt;
 2*1 #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Division: &lt;br /&gt;
 2/1 #This will equal 2.&lt;br /&gt;
&lt;br /&gt;
There are other operations, that you may want to pay closer attention to.&lt;br /&gt;
 &lt;br /&gt;
 #Exponentiation: &lt;br /&gt;
 2**2    #This will equal 4.&lt;br /&gt;
 &lt;br /&gt;
 #Square root: &lt;br /&gt;
 sqrt(4) #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Remainder: &lt;br /&gt;
 5%4     #This will equal 1.&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical “Hello, world!”, you would code:&lt;br /&gt;
 print(“Hello, world!”)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an if statement, followed by a colon. The next line is indented, and then tells that if statement what to do if the if statement is true. If it is not true, it moves on to the elif statement. Elif statements are used after if statements, but when there is still an if statement involved. There can be endless elif statements. Notice this uses the same syntax as the regular if statement. Lastly, if neither the if nor the elif statement(s) are true, there is an else statement. This will print if nothing above was true.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38880</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38880"/>
		<updated>2020-11-14T22:29:18Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: Hid VPython Basics, as it has been migrated to another article&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
Python is an interpreted, high-level programming language. As a general-purpose language, it is used for a variety of applications, which makes it an obvious choice for computational physics models, considering its shallow learning curve and syntactically simplistic features. It is also OS-independent, allowing it to be run on virtually any machine. &lt;br /&gt;
&lt;br /&gt;
===VPython===&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although VPython slightly differs from the actual Python programming language, the majority of functionality remains the same, including all syntax. For the sole purpose of this class, however, it is functionally equivalent to Python, which is why it is imperative to understand the underlying Python language. Most of the labs done this year (which includes any labs requiring the construction of a physics simulation model) will be done using the VPython.&lt;br /&gt;
&lt;br /&gt;
==Downloading/Installation==&lt;br /&gt;
&lt;br /&gt;
===Versions===&lt;br /&gt;
Python has two major versions: Python 2 and 3&lt;br /&gt;
&lt;br /&gt;
However, on January 1st, 2020, version 2.x was officially deprecated and no longer officially supported by the Python Foundation. As a result, the majority of the Python community have already migrated away from the dying version. In any case, Python 2.x has significant syntactical differences that Python 3.x is not backwards-compatible with (hence, the major version change), which is why this course will be attempting to adhere to the guidelines set by Python 3.&lt;br /&gt;
&lt;br /&gt;
===Downloading===&lt;br /&gt;
The latest stable version of Python 3 available is [https://www.python.org/downloads/release/python-390/ 3.9.0] (as of November 2020).&lt;br /&gt;
&lt;br /&gt;
Older versions of Python 3 can be found at [https://www.python.org/downloads/ https://www.python.org/downloads/].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this class, it is not necessary to download and install VPython, as we will be working with VPython through the virtual [https://www.glowscript.org/ GlowScript] environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Downloading==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
A variable is an item within your code that has information stored in it. This information can be a number, a string of letters, or anything really. &amp;lt;br&amp;gt;&lt;br /&gt;
Variables are identified by a name. The names of your variables should be simple, but logical. Avoid names that include spaces or dots, because Python does not like this syntax. Rather, it is best to separate two words in a variable name by capitalizing the second word, such as “myVariable”, or an underscore, such as “my_variable”. &amp;lt;br&amp;gt;&lt;br /&gt;
Storing items as a variable allows for easy access when they are needed later in your program. &amp;lt;br&amp;gt;&lt;br /&gt;
One last thing that is important to note is that you can reassign variables. For example, the code below is completely valid.&amp;lt;br&amp;gt;&lt;br /&gt;
 x = 5&lt;br /&gt;
 x = x + 2&lt;br /&gt;
When this code is finished running, x will equal 7. Although this is counterintuitive at first, it’s easy to get used to.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Math Operations==&lt;br /&gt;
&lt;br /&gt;
Math operations are simple in Python. The simple operations, as you might expect, are as follows:&lt;br /&gt;
 #Addition: &lt;br /&gt;
 1+2 #This will equal 3.&lt;br /&gt;
 &lt;br /&gt;
 #Subtraction: &lt;br /&gt;
 2-1 #This will equal 1.&lt;br /&gt;
 &lt;br /&gt;
 #Multiplication: &lt;br /&gt;
 2*1 #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Division: &lt;br /&gt;
 2/1 #This will equal 2.&lt;br /&gt;
&lt;br /&gt;
There are other operations, that you may want to pay closer attention to.&lt;br /&gt;
 &lt;br /&gt;
 #Exponentiation: &lt;br /&gt;
 2**2    #This will equal 4.&lt;br /&gt;
 &lt;br /&gt;
 #Square root: &lt;br /&gt;
 sqrt(4) #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Remainder: &lt;br /&gt;
 5%4     #This will equal 1.&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical “Hello, world!”, you would code:&lt;br /&gt;
 print(“Hello, world!”)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an if statement, followed by a colon. The next line is indented, and then tells that if statement what to do if the if statement is true. If it is not true, it moves on to the elif statement. Elif statements are used after if statements, but when there is still an if statement involved. There can be endless elif statements. Notice this uses the same syntax as the regular if statement. Lastly, if neither the if nor the elif statement(s) are true, there is an else statement. This will print if nothing above was true.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38873</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38873"/>
		<updated>2020-11-14T22:04:49Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: Added description of the Python programming language, and updated the description of VPython. Also deleted the downloading section for VPython and replaced it with instructions for Python 3 installation.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
===Python===&lt;br /&gt;
Python is an interpreted, high-level programming language. As a general-purpose language, it is used for a variety of applications, which makes it an obvious choice for computational physics models, considering its shallow learning curve and syntactically simplistic features. It is also OS-independent, allowing it to be run on virtually any machine. &lt;br /&gt;
&lt;br /&gt;
===VPython===&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although VPython slightly differs from the actual Python programming language, the majority of functionality remains the same, including all syntax. For the sole purpose of this class, however, it is functionally equivalent to Python, which is why it is imperative to understand the underlying Python language. Most of the labs done this year (which includes any labs requiring the construction of a physics simulation model) will be done using the VPython.&lt;br /&gt;
&lt;br /&gt;
==Downloading/Installation==&lt;br /&gt;
&lt;br /&gt;
===Versions===&lt;br /&gt;
Python has two major versions: Python 2 and 3&lt;br /&gt;
&lt;br /&gt;
However, on January 1st, 2020, version 2.x was officially deprecated and no longer officially supported by the Python Foundation. As a result, the majority of the Python community have already migrated away from the dying version. In any case, Python 2.x has significant syntactical differences that Python 3.x is not backwards-compatible with (hence, the major version change), which is why this course will be attempting to adhere to the guidelines set by Python 3.&lt;br /&gt;
&lt;br /&gt;
===Downloading===&lt;br /&gt;
The latest stable version of Python 3 available is [https://www.python.org/downloads/release/python-390/ 3.9.0] (as of November 2020).&lt;br /&gt;
&lt;br /&gt;
Older versions of Python 3 can be found at [https://www.python.org/downloads/ https://www.python.org/downloads/].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this class, it is not necessary to download and install VPython, as we will be working with VPython through the virtual [https://www.glowscript.org/ GlowScript] environment.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--==Downloading==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
A variable is an item within your code that has information stored in it. This information can be a number, a string of letters, or anything really. &amp;lt;br&amp;gt;&lt;br /&gt;
Variables are identified by a name. The names of your variables should be simple, but logical. Avoid names that include spaces or dots, because Python does not like this syntax. Rather, it is best to separate two words in a variable name by capitalizing the second word, such as “myVariable”, or an underscore, such as “my_variable”. &amp;lt;br&amp;gt;&lt;br /&gt;
Storing items as a variable allows for easy access when they are needed later in your program. &amp;lt;br&amp;gt;&lt;br /&gt;
One last thing that is important to note is that you can reassign variables. For example, the code below is completely valid.&amp;lt;br&amp;gt;&lt;br /&gt;
 x = 5&lt;br /&gt;
 x = x + 2&lt;br /&gt;
When this code is finished running, x will equal 7. Although this is counterintuitive at first, it’s easy to get used to.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Math Operations==&lt;br /&gt;
&lt;br /&gt;
Math operations are simple in Python. The simple operations, as you might expect, are as follows:&lt;br /&gt;
 #Addition: &lt;br /&gt;
 1+2 #This will equal 3.&lt;br /&gt;
 &lt;br /&gt;
 #Subtraction: &lt;br /&gt;
 2-1 #This will equal 1.&lt;br /&gt;
 &lt;br /&gt;
 #Multiplication: &lt;br /&gt;
 2*1 #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Division: &lt;br /&gt;
 2/1 #This will equal 2.&lt;br /&gt;
&lt;br /&gt;
There are other operations, that you may want to pay closer attention to.&lt;br /&gt;
 &lt;br /&gt;
 #Exponentiation: &lt;br /&gt;
 2**2    #This will equal 4.&lt;br /&gt;
 &lt;br /&gt;
 #Square root: &lt;br /&gt;
 sqrt(4) #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Remainder: &lt;br /&gt;
 5%4     #This will equal 1.&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical “Hello, world!”, you would code:&lt;br /&gt;
 print(“Hello, world!”)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an if statement, followed by a colon. The next line is indented, and then tells that if statement what to do if the if statement is true. If it is not true, it moves on to the elif statement. Elif statements are used after if statements, but when there is still an if statement involved. There can be endless elif statements. Notice this uses the same syntax as the regular if statement. Lastly, if neither the if nor the elif statement(s) are true, there is an else statement. This will print if nothing above was true.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38870</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=38870"/>
		<updated>2020-11-13T23:16:57Z</updated>

		<summary type="html">&lt;p&gt;Adsouza: Claimed wiki page for Fall 2020&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Claimed by Ashish D&#039;Souza for Fall 2020&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
VPython is an extension of the Python programming language that contains a 3D graphics module called Visual, which allows users to create simple simulations of physics problems. Its primary use is for educational purposes, although it has been used in research before in the past. Although it is slightly different from the actual Python program, it is similar enough for the purpose of this class. Most of the labs done this year will be done using the vPython program.&lt;br /&gt;
&lt;br /&gt;
==Downloading vPython==&lt;br /&gt;
In all cases you will need to have Python 2.7.9 installed. Future versions may also work, but be warned that it may cause VPython to behave erratically.&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_windows.html For Windows]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_mac.html For Mac]&lt;br /&gt;
&lt;br /&gt;
[http://vpython.org/contents/download_linux.html For Linux]&lt;br /&gt;
&lt;br /&gt;
Note for Linux: You can only install Classic VPython, which is no longer supported and may be missing some features and bug fixes that are present in the current version of VPython.&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can use GlowScript, a virtual environment that allows you to execute VPython code in your browser. You can create an account at [http://www.glowscript.org/ http://www.glowscript.org/]. Although this is useful, keep in mind that not all labs can be completed through GlowScript.&lt;br /&gt;
&lt;br /&gt;
=Python Basics=&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
&lt;br /&gt;
A variable is an item within your code that has information stored in it. This information can be a number, a string of letters, or anything really. &amp;lt;br&amp;gt;&lt;br /&gt;
Variables are identified by a name. The names of your variables should be simple, but logical. Avoid names that include spaces or dots, because Python does not like this syntax. Rather, it is best to separate two words in a variable name by capitalizing the second word, such as “myVariable”, or an underscore, such as “my_variable”. &amp;lt;br&amp;gt;&lt;br /&gt;
Storing items as a variable allows for easy access when they are needed later in your program. &amp;lt;br&amp;gt;&lt;br /&gt;
One last thing that is important to note is that you can reassign variables. For example, the code below is completely valid.&amp;lt;br&amp;gt;&lt;br /&gt;
 x = 5&lt;br /&gt;
 x = x + 2&lt;br /&gt;
When this code is finished running, x will equal 7. Although this is counterintuitive at first, it’s easy to get used to.&lt;br /&gt;
&lt;br /&gt;
==Comments==&lt;br /&gt;
&lt;br /&gt;
Comments are useful when you want to include a note or a quick explanation in your code that will make it easier to understand later. Comments are sections of code that the computer will skip in execution, so it will not actually be executed when your program runs. There are two types of comments that Python uses, single line comments and multi-line comments.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Single Line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a single line comment (the most common comments in Python) type a hash character (#) at the beginning of anything you would like to comment out. Note, when &amp;quot;#&amp;quot; is in a line of code, the rest of the code following the # will be ignored by the computer when your code runs.&lt;br /&gt;
&lt;br /&gt;
 # This is a comment.&lt;br /&gt;
 &lt;br /&gt;
 a = 4 # and so is this&lt;br /&gt;
 &lt;br /&gt;
 # b = 4 # and so is this entire line, be careful!&lt;br /&gt;
&lt;br /&gt;
Here is an example of comment use that you might see in a lab:&lt;br /&gt;
&lt;br /&gt;
 myTemp = 4 #This is the temperature in Celsius.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Multi-line Comments&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To create a multi-line comment (usually reserved for longer explanations or instructions that cannot fit on one line) type three opening and closing quotation marks, like so:&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this &lt;br /&gt;
     is&lt;br /&gt;
     a&lt;br /&gt;
     multi-line&lt;br /&gt;
     comment &lt;br /&gt;
     example &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;&amp;quot;&amp;quot; this is also an example, but on only one line&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Be careful! Unlike the single line comments, multi-line comments require a start and a stop (if you forget to close your comment or forget the third quotation mark then that will cause an error in your code).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Main Uses&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
- Longer variable explanation (units, where the data comes from, etc)&lt;br /&gt;
&lt;br /&gt;
- Comment out code (to save for later, instead of deleting it)&lt;br /&gt;
&lt;br /&gt;
- Instructions&lt;br /&gt;
&lt;br /&gt;
- Notes to self&lt;br /&gt;
&lt;br /&gt;
==Math Operations==&lt;br /&gt;
&lt;br /&gt;
Math operations are simple in Python. The simple operations, as you might expect, are as follows:&lt;br /&gt;
 #Addition: &lt;br /&gt;
 1+2 #This will equal 3.&lt;br /&gt;
 &lt;br /&gt;
 #Subtraction: &lt;br /&gt;
 2-1 #This will equal 1.&lt;br /&gt;
 &lt;br /&gt;
 #Multiplication: &lt;br /&gt;
 2*1 #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Division: &lt;br /&gt;
 2/1 #This will equal 2.&lt;br /&gt;
&lt;br /&gt;
There are other operations, that you may want to pay closer attention to.&lt;br /&gt;
 &lt;br /&gt;
 #Exponentiation: &lt;br /&gt;
 2**2    #This will equal 4.&lt;br /&gt;
 &lt;br /&gt;
 #Square root: &lt;br /&gt;
 sqrt(4) #This will equal 2.&lt;br /&gt;
 &lt;br /&gt;
 #Remainder: &lt;br /&gt;
 5%4     #This will equal 1.&lt;br /&gt;
&lt;br /&gt;
==Print Function==&lt;br /&gt;
&lt;br /&gt;
In order to see any of the information we’ve listed above, you have to actually print it. For example, the code below will run but will not provide you with an output.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
Instead, you have to print this information in order to see the answer when the code is finished running. You can do this in two ways. First, you can directly imbed the code in your print statement.&lt;br /&gt;
 print(1 + 1)&lt;br /&gt;
Or, you can create the variable and then print the variable.&lt;br /&gt;
 x = 1 + 1&lt;br /&gt;
 print(x)&lt;br /&gt;
Either one is valid!&lt;br /&gt;
If you would like to print something other than a variable, include quotations around it. For example, if you wanted to print the typical “Hello, world!”, you would code:&lt;br /&gt;
 print(“Hello, world!”)&lt;br /&gt;
The quotations are the important takeaway here.&lt;br /&gt;
&lt;br /&gt;
==Conditional==&lt;br /&gt;
A conditional involves an “if” statement. “If this thing is true, do this”, for example. Conditionals are useful in physics if you want to perform different things on a variable, depending on certain conditions.&lt;br /&gt;
 if x &amp;gt; 1:&lt;br /&gt;
 	print(“x is greater than 1”)&lt;br /&gt;
 elif x = 1:&lt;br /&gt;
 	print(“x is equal to 1”)&lt;br /&gt;
 else:&lt;br /&gt;
 	print(“x is less than 1”)&lt;br /&gt;
Above is the typical syntax you would see for a conditional. Notice the conditional starts with an if statement, followed by a colon. The next line is indented, and then tells that if statement what to do if the if statement is true. If it is not true, it moves on to the elif statement. Elif statements are used after if statements, but when there is still an if statement involved. There can be endless elif statements. Notice this uses the same syntax as the regular if statement. Lastly, if neither the if nor the elif statement(s) are true, there is an else statement. This will print if nothing above was true.&lt;br /&gt;
&lt;br /&gt;
==Loop==&lt;br /&gt;
A loop iterates through each item in a list or range. Loops can be useful in physics because they are vital to update equations. Loops will automatically update the information for you, rather than having to write out the long iterative process yourself. Below are examples of for loops and while loops.&lt;br /&gt;
 for i in range(1,11):&lt;br /&gt;
 	print(i)&lt;br /&gt;
The statement above will print:&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
 10&lt;br /&gt;
Notice it does not print 11. When inputting a range in Python, the last number is not included. Notice how the for loop states “for”, and then a variable, and then a range, and then a colon. This is then followed by a statement that tells what to do for each iteration in the loop. Notice it is indented!&lt;br /&gt;
 while i &amp;gt; 1:&lt;br /&gt;
 	print(i)&lt;br /&gt;
This is an example of a while loop. While i is greater than 1, the code will print i. The syntax is similar to the for loop.&lt;br /&gt;
&lt;br /&gt;
==Equal Signs==&lt;br /&gt;
&lt;br /&gt;
“=” and “==” mean two different things in Python. When assigning a variable to a value, you use one equal sign:&lt;br /&gt;
 x = 2&lt;br /&gt;
However, when you are using it to check if something is equal to another thing (i.e. in an if statement), you use two equal signs:&lt;br /&gt;
 if x == 2:&lt;br /&gt;
 	print(“x equals 2)&lt;br /&gt;
&lt;br /&gt;
=VPython Basics=&lt;br /&gt;
&lt;br /&gt;
In this section we will analyze some of the objects utilized by VPython. Each object is more or less self-explanatory with equally clear fields within.&lt;br /&gt;
&lt;br /&gt;
==Starting Your VPython Program==&lt;br /&gt;
To begin with, note that every VPython program must begin with these two lines of code:&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import*&lt;br /&gt;
    &lt;br /&gt;
The scene, or visual where you see your code occur, has a width and a height. You can alter them, as seen below.&lt;br /&gt;
 scene.width = 1024&lt;br /&gt;
 scene.height = 760&lt;br /&gt;
&lt;br /&gt;
==Vectors==&lt;br /&gt;
You can access each component of the vector with pos.x, pos.y, or pos.z, depending on which component you want. You access an object&#039;s field with a period following the variable name.&lt;br /&gt;
&lt;br /&gt;
 pos = vector(1, 2, 3)&lt;br /&gt;
 xComponent = pos.x  #This value would be 1&lt;br /&gt;
 yComponent = pos.y  #This value would be 2&lt;br /&gt;
 zComponent = pos.z. #This value would be 3&lt;br /&gt;
&lt;br /&gt;
You can add two or more vectors together and you can multiply a vector by a scalar. Keep in mind you cannot add a vector and a scalar.&lt;br /&gt;
&lt;br /&gt;
 #Adding&lt;br /&gt;
 A = vector(1, 2, 3)&lt;br /&gt;
 B = vector(4, 5, 6)&lt;br /&gt;
 C = A + B  # The value of C is now (5, 7, 9)&lt;br /&gt;
 &lt;br /&gt;
 # Multiplying&lt;br /&gt;
 D = 5 * C. # The value of D is now (25, 35, 45)&lt;br /&gt;
&lt;br /&gt;
To get the magnitude of or to normalize a vector, use the appropriate function.&lt;br /&gt;
&lt;br /&gt;
 initialPos = vector(10, 3, 0)&lt;br /&gt;
 finalPos = vector(30, 15, 0)&lt;br /&gt;
 deltaR = finalPos - initialPos # -&amp;gt; vector(20, 12, 0)&lt;br /&gt;
 rMag = mag(finalPos)&lt;br /&gt;
 rHat = norm(finalPos)&lt;br /&gt;
 errorDemo = magR + finalPos # -&amp;gt; error; causes your program to crash&lt;br /&gt;
&lt;br /&gt;
==Shapes==&lt;br /&gt;
&lt;br /&gt;
There are a number of different shapes you can create for visual reference in the vPython program. These will be used quite frequently in lab to observe things like momentum, force, etc. If you were to make, say, a ball, you would want to draw a sphere. It has a position field, a radius field, and a color field. When creating a new instance of an object, each field is comma separated. You access each field the same way as we did with the position vector.&lt;br /&gt;
 ball = sphere(pos = vector(10, 10, 10), radius = 9e2, color = color.red)&lt;br /&gt;
 ballColor = ball.color&lt;br /&gt;
 ballPos = ball.pos&lt;br /&gt;
 ballRadius = ball.radius&lt;br /&gt;
&lt;br /&gt;
You can draw arrows. These also have a color and position field, but instead of a radius, they have an axis that determines their length. These arrows can be used to represent the magnitude of the force or the momentum or anything else the lab asks you to make. &lt;br /&gt;
 velocityArrow = arrow(color = color.blue, pos = vector(-10, -10, -10), axis = velocity * vScale)&lt;br /&gt;
&lt;br /&gt;
There are also boxes. They have a position vector and a size vector.&lt;br /&gt;
 myBox = box(pos = vector(50, 50, 50), size = vector(20, 15, 12))&lt;br /&gt;
&lt;br /&gt;
You can draw helixes, which are useful for depicting springs. They have a position field, a color field, a thickness field, a radius field, and a field for the number of coils.&lt;br /&gt;
 spring = helix(pos=ceiling.pos, color=color.cyan, thickness=.003, coils=40, radius=0.015)&lt;br /&gt;
&lt;br /&gt;
==Tracing==&lt;br /&gt;
&lt;br /&gt;
If you want to trace a moving object, you can have a curve follow it by adding to it every time step. This will show the entire path the object has traveled during the simulation.&lt;br /&gt;
 posTrace = curve(color = color.yellow)&lt;br /&gt;
 trail.append(ball.pos)&lt;br /&gt;
&lt;br /&gt;
==Graphs==&lt;br /&gt;
&lt;br /&gt;
You also have the option of making graphs as your program progresses; this is particularly useful for potential vs kinetic energy.&lt;br /&gt;
 Kgraph = gcurve(color = color.cyan)&lt;br /&gt;
 Ugraph = gcurve(color = color.yellow)&lt;br /&gt;
 KplusUgraph = gcurve(color = color.red)&lt;br /&gt;
 # For each time step...&lt;br /&gt;
 Kgraph.plot(pos = (t, Kenergy))&lt;br /&gt;
 Ugraph.plot(pos = (t, Uenergy))&lt;br /&gt;
 KplusUgraph.plot(pos = (t, Kenergy + Uenergy))&lt;br /&gt;
&lt;br /&gt;
By updating the fields of whatever objects you decide to use and by using any intermediate variables necessary, you&#039;re able to draw and compute what you&#039;ll need for this course.&lt;/div&gt;</summary>
		<author><name>Adsouza</name></author>
	</entry>
</feed>