<?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=Ewang328</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=Ewang328"/>
	<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/Special:Contributions/Ewang328"/>
	<updated>2026-04-11T21:29:53Z</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=39161</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39161"/>
		<updated>2021-04-19T02:28:04Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Loop */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that variables can be thought of as &amp;quot;objects&amp;quot; or abstract data types representing various forms of information.&lt;br /&gt;
&lt;br /&gt;
===Declaring a Variable===&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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;
&lt;br /&gt;
It is possible to assign a new variable to a variable that has already been assigned as well. The new variable will store the information that the original variable was already assigned.&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
===Data Types===&lt;br /&gt;
&#039;&#039;&#039;Integer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
An integer is a whole number. It can be positive or negative but cannot contain any decimals. Integers have unlimited length.&lt;br /&gt;
&lt;br /&gt;
Examples of integers are:&lt;br /&gt;
 x = 1&lt;br /&gt;
 y = 3452374791834&lt;br /&gt;
 z = -289&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Float&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A float, also known as a &amp;quot;floating point number,&amp;quot; is a number that contains one more decimals. A float can be either positive or negative.&lt;br /&gt;
&lt;br /&gt;
Examples of floats are:&lt;br /&gt;
 w = 24e4&lt;br /&gt;
 x = 10.2&lt;br /&gt;
 y = 1.0&lt;br /&gt;
 z = -23.9&lt;br /&gt;
&lt;br /&gt;
Note that a whole number can be made a float by adding a &amp;lt;code&amp;gt;.0&amp;lt;/code&amp;gt; at the end of the number. Floats can also be scientific numbers with an &amp;quot;e&amp;quot; to indicate a power of 10.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Complex&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Complex numbers are numbers that be expressed in the form a + bi, where a and b are real numbers, and i is a symbol representing the imaginary unit. The imaginary unit satisfies the equation &amp;lt;math&amp;gt;i^2=-1&amp;lt;/math&amp;gt;. In python, complex numbers are written with a &amp;quot;j&amp;quot; as the imaginary part.&lt;br /&gt;
&lt;br /&gt;
Examples of complex numbers are:&lt;br /&gt;
 x = 3+5j&lt;br /&gt;
 y = 5j&lt;br /&gt;
 z = -8j&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Strings&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Strings are sequences of characters, including alphabetical characters and numerical ones. They are surrounded by either single quotation marks are double quotation marks. Strings are immutable, meaning that once they are defined, they cannot be changed. Only certain Python methods such as &amp;lt;code&amp;gt;replace()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;join()&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;split()&amp;lt;/code&amp;gt; can modify strings.&lt;br /&gt;
&lt;br /&gt;
Examples of strings are:&lt;br /&gt;
 a = &amp;quot;hello&amp;quot;&lt;br /&gt;
 b = &#039;c&#039;&lt;br /&gt;
 c = &#039;934&#039;&lt;br /&gt;
&lt;br /&gt;
Note that while the variable c is made up of numbers, it is still a string because of the quotation marks. Because of this, it cannot be used in mathematical operations until it is converted to a numeric type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Boolean&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Booleans represent one of two values: &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;False&amp;lt;/code&amp;gt;. In programming, the user often needs to know if a certain expression is True or False. Comparisons are often evaluated to return a Boolean answer. Some examples of comparisons are:&lt;br /&gt;
&lt;br /&gt;
 10 &amp;gt; 9 # True&lt;br /&gt;
 10 == 9 # False&lt;br /&gt;
 10 &amp;lt; 9 # False&lt;br /&gt;
&lt;br /&gt;
Note that &amp;lt;code&amp;gt;==&amp;lt;/code&amp;gt; is used when seeing if two integers are the same or not. This is because &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; is reserved for declaring variables. Be careful to not use &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; in a comparison.&lt;br /&gt;
&lt;br /&gt;
Two types are also never equal to each other, even if they seem to contain the same information within them.&lt;br /&gt;
 a = &amp;quot;9&amp;quot;&lt;br /&gt;
 b = 9&lt;br /&gt;
 &lt;br /&gt;
 a == b # False&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;List&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Lists in Python can be used to store multiple items in a single variable. They are created using square brackets and can contain different data types. Lists are mutable, meaning that the user can change, add, and remove items in the list even after it has been created.&lt;br /&gt;
&lt;br /&gt;
Examples of lists are:&lt;br /&gt;
 mylist = [&amp;quot;dog&amp;quot;, &amp;quot;cat&amp;quot;, &amp;quot;bird&amp;quot;]&lt;br /&gt;
 numberlist = [9, 0, 3, 4]&lt;br /&gt;
 mixedlist = [&amp;quot;tree&amp;quot;, 2, 0, &amp;quot;frog&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
Lists can also be indexed into. By indexing into a list, the user can get the data at a specific spot. Note that indexing starts at the number 0, meaning that the first item in the list can only be accessed by using the number 0.&lt;br /&gt;
 mylist[0] # &amp;quot;dog&amp;quot;&lt;br /&gt;
 mylist[1] # &amp;quot;cat&amp;quot;&lt;br /&gt;
 mylist[2] # &amp;quot;bird&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tuple&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Like lists, tuples are also used to store multiple items in a single variable. However, unlike lists, tuples are immutable, meaning that they cannot be changed once being created. Tuples are created using curly brackets. A comma is necessary in the creation of a tuple. Therefore, to create one item, you have to add a comma after the item, otherwise Python will not recognize it as a tuple.&lt;br /&gt;
&lt;br /&gt;
Examples of tuples are:&lt;br /&gt;
 thistuple = {&amp;quot;cookies&amp;quot;, &amp;quot;cake&amp;quot;}&lt;br /&gt;
 booleantuple = {True, False, True}&lt;br /&gt;
&lt;br /&gt;
Tuples can also be indexed into like lists.&lt;br /&gt;
&lt;br /&gt;
===Type Conversion===&lt;br /&gt;
Some data types in Python can be converted from one type into another with certain methods. It&#039;s important to use the same type when using operations in Python. Only numeric data types can be used in mathematical operations. It is possible to convert a string into a number data type with type conversion.&lt;br /&gt;
&lt;br /&gt;
To convert from one type into another, use &amp;lt;code&amp;gt;int()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;float()&amp;lt;/code&amp;gt; methods.&lt;br /&gt;
 x = 3 # int&lt;br /&gt;
 y = 2.9 # float&lt;br /&gt;
 z = &amp;quot;4&amp;quot; # string&lt;br /&gt;
 &lt;br /&gt;
 # convert from int to float:&lt;br /&gt;
 a = float(x)&lt;br /&gt;
 &lt;br /&gt;
 # convert from float to int:&lt;br /&gt;
 b = int(y)&lt;br /&gt;
 &lt;br /&gt;
 # convert from string to int:&lt;br /&gt;
 c = int(z)&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. Note that the block of code under a loop must be indented.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;While Loops&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;code&amp;gt;while&amp;lt;/code&amp;gt; loop will often be used in physics to update time. With a &amp;lt;code&amp;gt;while&amp;lt;/code&amp;gt; loop, a set of statements can be executed as long as the condition is true. For physics, this is often used when time is below a certain point. Within the while loop, time is incremented to mock the passing of time until the while loop is no longer true.&lt;br /&gt;
&lt;br /&gt;
 t = 0&lt;br /&gt;
 deltat = 0.1&lt;br /&gt;
 x = 1&lt;br /&gt;
 while t &amp;lt; 1:&lt;br /&gt;
     x += 1&lt;br /&gt;
     t += 1&lt;br /&gt;
&lt;br /&gt;
After this is executed, x will equal 10.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;For Loops&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;code&amp;gt;for&amp;lt;/code&amp;gt; loop is used when iterating over a sequence, such as a list, tuple, or string. When using &amp;lt;code&amp;gt;for&amp;lt;/code&amp;gt;, the program iterates through each component of whatever is specified.&lt;br /&gt;
&lt;br /&gt;
To print each component of a list of animals:&lt;br /&gt;
 animals = [&amp;quot;dog&amp;quot;, &amp;quot;cat&amp;quot;, &amp;quot;bird&amp;quot;]&lt;br /&gt;
 for x in animals:&lt;br /&gt;
     print(x)&lt;br /&gt;
&lt;br /&gt;
To print each letter in the word &amp;quot;yellowjackets&amp;quot;:&lt;br /&gt;
 for x in &amp;quot;yellowjackets&amp;quot;:&lt;br /&gt;
     print(x)&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39160</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39160"/>
		<updated>2021-04-19T02:21:37Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Loop */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that variables can be thought of as &amp;quot;objects&amp;quot; or abstract data types representing various forms of information.&lt;br /&gt;
&lt;br /&gt;
===Declaring a Variable===&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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;
&lt;br /&gt;
It is possible to assign a new variable to a variable that has already been assigned as well. The new variable will store the information that the original variable was already assigned.&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
===Data Types===&lt;br /&gt;
&#039;&#039;&#039;Integer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
An integer is a whole number. It can be positive or negative but cannot contain any decimals. Integers have unlimited length.&lt;br /&gt;
&lt;br /&gt;
Examples of integers are:&lt;br /&gt;
 x = 1&lt;br /&gt;
 y = 3452374791834&lt;br /&gt;
 z = -289&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Float&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A float, also known as a &amp;quot;floating point number,&amp;quot; is a number that contains one more decimals. A float can be either positive or negative.&lt;br /&gt;
&lt;br /&gt;
Examples of floats are:&lt;br /&gt;
 w = 24e4&lt;br /&gt;
 x = 10.2&lt;br /&gt;
 y = 1.0&lt;br /&gt;
 z = -23.9&lt;br /&gt;
&lt;br /&gt;
Note that a whole number can be made a float by adding a &amp;lt;code&amp;gt;.0&amp;lt;/code&amp;gt; at the end of the number. Floats can also be scientific numbers with an &amp;quot;e&amp;quot; to indicate a power of 10.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Complex&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Complex numbers are numbers that be expressed in the form a + bi, where a and b are real numbers, and i is a symbol representing the imaginary unit. The imaginary unit satisfies the equation &amp;lt;math&amp;gt;i^2=-1&amp;lt;/math&amp;gt;. In python, complex numbers are written with a &amp;quot;j&amp;quot; as the imaginary part.&lt;br /&gt;
&lt;br /&gt;
Examples of complex numbers are:&lt;br /&gt;
 x = 3+5j&lt;br /&gt;
 y = 5j&lt;br /&gt;
 z = -8j&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Strings&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Strings are sequences of characters, including alphabetical characters and numerical ones. They are surrounded by either single quotation marks are double quotation marks. Strings are immutable, meaning that once they are defined, they cannot be changed. Only certain Python methods such as &amp;lt;code&amp;gt;replace()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;join()&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;split()&amp;lt;/code&amp;gt; can modify strings.&lt;br /&gt;
&lt;br /&gt;
Examples of strings are:&lt;br /&gt;
 a = &amp;quot;hello&amp;quot;&lt;br /&gt;
 b = &#039;c&#039;&lt;br /&gt;
 c = &#039;934&#039;&lt;br /&gt;
&lt;br /&gt;
Note that while the variable c is made up of numbers, it is still a string because of the quotation marks. Because of this, it cannot be used in mathematical operations until it is converted to a numeric type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Boolean&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Booleans represent one of two values: &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;False&amp;lt;/code&amp;gt;. In programming, the user often needs to know if a certain expression is True or False. Comparisons are often evaluated to return a Boolean answer. Some examples of comparisons are:&lt;br /&gt;
&lt;br /&gt;
 10 &amp;gt; 9 # True&lt;br /&gt;
 10 == 9 # False&lt;br /&gt;
 10 &amp;lt; 9 # False&lt;br /&gt;
&lt;br /&gt;
Note that &amp;lt;code&amp;gt;==&amp;lt;/code&amp;gt; is used when seeing if two integers are the same or not. This is because &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; is reserved for declaring variables. Be careful to not use &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; in a comparison.&lt;br /&gt;
&lt;br /&gt;
Two types are also never equal to each other, even if they seem to contain the same information within them.&lt;br /&gt;
 a = &amp;quot;9&amp;quot;&lt;br /&gt;
 b = 9&lt;br /&gt;
 &lt;br /&gt;
 a == b # False&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;List&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Lists in Python can be used to store multiple items in a single variable. They are created using square brackets and can contain different data types. Lists are mutable, meaning that the user can change, add, and remove items in the list even after it has been created.&lt;br /&gt;
&lt;br /&gt;
Examples of lists are:&lt;br /&gt;
 mylist = [&amp;quot;dog&amp;quot;, &amp;quot;cat&amp;quot;, &amp;quot;bird&amp;quot;]&lt;br /&gt;
 numberlist = [9, 0, 3, 4]&lt;br /&gt;
 mixedlist = [&amp;quot;tree&amp;quot;, 2, 0, &amp;quot;frog&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
Lists can also be indexed into. By indexing into a list, the user can get the data at a specific spot. Note that indexing starts at the number 0, meaning that the first item in the list can only be accessed by using the number 0.&lt;br /&gt;
 mylist[0] # &amp;quot;dog&amp;quot;&lt;br /&gt;
 mylist[1] # &amp;quot;cat&amp;quot;&lt;br /&gt;
 mylist[2] # &amp;quot;bird&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tuple&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Like lists, tuples are also used to store multiple items in a single variable. However, unlike lists, tuples are immutable, meaning that they cannot be changed once being created. Tuples are created using curly brackets. A comma is necessary in the creation of a tuple. Therefore, to create one item, you have to add a comma after the item, otherwise Python will not recognize it as a tuple.&lt;br /&gt;
&lt;br /&gt;
Examples of tuples are:&lt;br /&gt;
 thistuple = {&amp;quot;cookies&amp;quot;, &amp;quot;cake&amp;quot;}&lt;br /&gt;
 booleantuple = {True, False, True}&lt;br /&gt;
&lt;br /&gt;
Tuples can also be indexed into like lists.&lt;br /&gt;
&lt;br /&gt;
===Type Conversion===&lt;br /&gt;
Some data types in Python can be converted from one type into another with certain methods. It&#039;s important to use the same type when using operations in Python. Only numeric data types can be used in mathematical operations. It is possible to convert a string into a number data type with type conversion.&lt;br /&gt;
&lt;br /&gt;
To convert from one type into another, use &amp;lt;code&amp;gt;int()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;float()&amp;lt;/code&amp;gt; methods.&lt;br /&gt;
 x = 3 # int&lt;br /&gt;
 y = 2.9 # float&lt;br /&gt;
 z = &amp;quot;4&amp;quot; # string&lt;br /&gt;
 &lt;br /&gt;
 # convert from int to float:&lt;br /&gt;
 a = float(x)&lt;br /&gt;
 &lt;br /&gt;
 # convert from float to int:&lt;br /&gt;
 b = int(y)&lt;br /&gt;
 &lt;br /&gt;
 # convert from string to int:&lt;br /&gt;
 c = int(z)&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.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;For Loops&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;code&amp;gt;for&amp;lt;/code&amp;gt; loop is used when iterating over a sequence, such as a list, tuple, or string. When using &amp;lt;code&amp;gt;for&amp;lt;/code&amp;gt;, the program iterates through each component of whatever is specified.&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39158</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39158"/>
		<updated>2021-04-19T02:11:39Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that variables can be thought of as &amp;quot;objects&amp;quot; or abstract data types representing various forms of information.&lt;br /&gt;
&lt;br /&gt;
===Declaring a Variable===&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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;
&lt;br /&gt;
It is possible to assign a new variable to a variable that has already been assigned as well. The new variable will store the information that the original variable was already assigned.&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
===Data Types===&lt;br /&gt;
&#039;&#039;&#039;Integer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
An integer is a whole number. It can be positive or negative but cannot contain any decimals. Integers have unlimited length.&lt;br /&gt;
&lt;br /&gt;
Examples of integers are:&lt;br /&gt;
 x = 1&lt;br /&gt;
 y = 3452374791834&lt;br /&gt;
 z = -289&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Float&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A float, also known as a &amp;quot;floating point number,&amp;quot; is a number that contains one more decimals. A float can be either positive or negative.&lt;br /&gt;
&lt;br /&gt;
Examples of floats are:&lt;br /&gt;
 w = 24e4&lt;br /&gt;
 x = 10.2&lt;br /&gt;
 y = 1.0&lt;br /&gt;
 z = -23.9&lt;br /&gt;
&lt;br /&gt;
Note that a whole number can be made a float by adding a &amp;lt;code&amp;gt;.0&amp;lt;/code&amp;gt; at the end of the number. Floats can also be scientific numbers with an &amp;quot;e&amp;quot; to indicate a power of 10.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Complex&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Complex numbers are numbers that be expressed in the form a + bi, where a and b are real numbers, and i is a symbol representing the imaginary unit. The imaginary unit satisfies the equation &amp;lt;math&amp;gt;i^2=-1&amp;lt;/math&amp;gt;. In python, complex numbers are written with a &amp;quot;j&amp;quot; as the imaginary part.&lt;br /&gt;
&lt;br /&gt;
Examples of complex numbers are:&lt;br /&gt;
 x = 3+5j&lt;br /&gt;
 y = 5j&lt;br /&gt;
 z = -8j&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Strings&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Strings are sequences of characters, including alphabetical characters and numerical ones. They are surrounded by either single quotation marks are double quotation marks. Strings are immutable, meaning that once they are defined, they cannot be changed. Only certain Python methods such as &amp;lt;code&amp;gt;replace()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;join()&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;split()&amp;lt;/code&amp;gt; can modify strings.&lt;br /&gt;
&lt;br /&gt;
Examples of strings are:&lt;br /&gt;
 a = &amp;quot;hello&amp;quot;&lt;br /&gt;
 b = &#039;c&#039;&lt;br /&gt;
 c = &#039;934&#039;&lt;br /&gt;
&lt;br /&gt;
Note that while the variable c is made up of numbers, it is still a string because of the quotation marks. Because of this, it cannot be used in mathematical operations until it is converted to a numeric type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Boolean&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Booleans represent one of two values: &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;False&amp;lt;/code&amp;gt;. In programming, the user often needs to know if a certain expression is True or False. Comparisons are often evaluated to return a Boolean answer. Some examples of comparisons are:&lt;br /&gt;
&lt;br /&gt;
 10 &amp;gt; 9 # True&lt;br /&gt;
 10 == 9 # False&lt;br /&gt;
 10 &amp;lt; 9 # False&lt;br /&gt;
&lt;br /&gt;
Note that &amp;lt;code&amp;gt;==&amp;lt;/code&amp;gt; is used when seeing if two integers are the same or not. This is because &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; is reserved for declaring variables. Be careful to not use &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; in a comparison.&lt;br /&gt;
&lt;br /&gt;
Two types are also never equal to each other, even if they seem to contain the same information within them.&lt;br /&gt;
 a = &amp;quot;9&amp;quot;&lt;br /&gt;
 b = 9&lt;br /&gt;
 &lt;br /&gt;
 a == b # False&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;List&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Lists in Python can be used to store multiple items in a single variable. They are created using square brackets and can contain different data types. Lists are mutable, meaning that the user can change, add, and remove items in the list even after it has been created.&lt;br /&gt;
&lt;br /&gt;
Examples of lists are:&lt;br /&gt;
 mylist = [&amp;quot;dog&amp;quot;, &amp;quot;cat&amp;quot;, &amp;quot;bird&amp;quot;]&lt;br /&gt;
 numberlist = [9, 0, 3, 4]&lt;br /&gt;
 mixedlist = [&amp;quot;tree&amp;quot;, 2, 0, &amp;quot;frog&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
Lists can also be indexed into. By indexing into a list, the user can get the data at a specific spot. Note that indexing starts at the number 0, meaning that the first item in the list can only be accessed by using the number 0.&lt;br /&gt;
 mylist[0] # &amp;quot;dog&amp;quot;&lt;br /&gt;
 mylist[1] # &amp;quot;cat&amp;quot;&lt;br /&gt;
 mylist[2] # &amp;quot;bird&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tuple&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Like lists, tuples are also used to store multiple items in a single variable. However, unlike lists, tuples are immutable, meaning that they cannot be changed once being created. Tuples are created using curly brackets. A comma is necessary in the creation of a tuple. Therefore, to create one item, you have to add a comma after the item, otherwise Python will not recognize it as a tuple.&lt;br /&gt;
&lt;br /&gt;
Examples of tuples are:&lt;br /&gt;
 thistuple = {&amp;quot;cookies&amp;quot;, &amp;quot;cake&amp;quot;}&lt;br /&gt;
 booleantuple = {True, False, True}&lt;br /&gt;
&lt;br /&gt;
Tuples can also be indexed into like lists.&lt;br /&gt;
&lt;br /&gt;
===Type Conversion===&lt;br /&gt;
Some data types in Python can be converted from one type into another with certain methods. It&#039;s important to use the same type when using operations in Python. Only numeric data types can be used in mathematical operations. It is possible to convert a string into a number data type with type conversion.&lt;br /&gt;
&lt;br /&gt;
To convert from one type into another, use &amp;lt;code&amp;gt;int()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;float()&amp;lt;/code&amp;gt; methods.&lt;br /&gt;
 x = 3 # int&lt;br /&gt;
 y = 2.9 # float&lt;br /&gt;
 z = &amp;quot;4&amp;quot; # string&lt;br /&gt;
 &lt;br /&gt;
 # convert from int to float:&lt;br /&gt;
 a = float(x)&lt;br /&gt;
 &lt;br /&gt;
 # convert from float to int:&lt;br /&gt;
 b = int(y)&lt;br /&gt;
 &lt;br /&gt;
 # convert from string to int:&lt;br /&gt;
 c = int(z)&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39155</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39155"/>
		<updated>2021-04-19T02:04:43Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Data Types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that variables can be thought of as &amp;quot;objects&amp;quot; or abstract data types representing various forms of information.&lt;br /&gt;
&lt;br /&gt;
===Declaring a Variable===&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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;
&lt;br /&gt;
It is possible to assign a new variable to a variable that has already been assigned as well. The new variable will store the information that the original variable was already assigned.&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
===Data Types===&lt;br /&gt;
&#039;&#039;&#039;Integer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
An integer is a whole number. It can be positive or negative but cannot contain any decimals. Integers have unlimited length.&lt;br /&gt;
&lt;br /&gt;
Examples of integers are:&lt;br /&gt;
 x = 1&lt;br /&gt;
 y = 3452374791834&lt;br /&gt;
 z = -289&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Float&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A float, also known as a &amp;quot;floating point number,&amp;quot; is a number that contains one more decimals. A float can be either positive or negative.&lt;br /&gt;
&lt;br /&gt;
Examples of floats are:&lt;br /&gt;
 w = 24e4&lt;br /&gt;
 x = 10.2&lt;br /&gt;
 y = 1.0&lt;br /&gt;
 z = -23.9&lt;br /&gt;
&lt;br /&gt;
Note that a whole number can be made a float by adding a &amp;lt;code&amp;gt;.0&amp;lt;/code&amp;gt; at the end of the number. Floats can also be scientific numbers with an &amp;quot;e&amp;quot; to indicate a power of 10.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Complex&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Complex numbers are numbers that be expressed in the form a + bi, where a and b are real numbers, and i is a symbol representing the imaginary unit. The imaginary unit satisfies the equation &amp;lt;math&amp;gt;i^2=-1&amp;lt;/math&amp;gt;. In python, complex numbers are written with a &amp;quot;j&amp;quot; as the imaginary part.&lt;br /&gt;
&lt;br /&gt;
Examples of complex numbers are:&lt;br /&gt;
 x = 3+5j&lt;br /&gt;
 y = 5j&lt;br /&gt;
 z = -8j&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Strings&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Strings are sequences of characters, including alphabetical characters and numerical ones. They are surrounded by either single quotation marks are double quotation marks. Strings are immutable, meaning that once they are defined, they cannot be changed. Only certain Python methods such as &amp;lt;code&amp;gt;replace()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;join()&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;split()&amp;lt;/code&amp;gt; can modify strings.&lt;br /&gt;
&lt;br /&gt;
Examples of strings are:&lt;br /&gt;
 a = &amp;quot;hello&amp;quot;&lt;br /&gt;
 b = &#039;c&#039;&lt;br /&gt;
 c = &#039;934&#039;&lt;br /&gt;
&lt;br /&gt;
Note that while the variable c is made up of numbers, it is still a string because of the quotation marks. Because of this, it cannot be used in mathematical operations until it is converted to a numeric type.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Boolean&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Booleans represent one of two values: &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;False&amp;lt;/code&amp;gt;. In programming, the user often needs to know if a certain expression is True or False. Comparisons are often evaluated to return a Boolean answer. Some examples of comparisons are:&lt;br /&gt;
&lt;br /&gt;
 10 &amp;gt; 9 # True&lt;br /&gt;
 10 == 9 # False&lt;br /&gt;
 10 &amp;lt; 9 # False&lt;br /&gt;
&lt;br /&gt;
Note that &amp;lt;code&amp;gt;==&amp;lt;/code&amp;gt; is used when seeing if two integers are the same or not. This is because &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; is reserved for declaring variables. Be careful to not use &amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt; in a comparison.&lt;br /&gt;
&lt;br /&gt;
Two types are also never equal to each other, even if they seem to contain the same information within them.&lt;br /&gt;
 a = &amp;quot;9&amp;quot;&lt;br /&gt;
 b = 9&lt;br /&gt;
 &lt;br /&gt;
 a == b # False&lt;br /&gt;
&lt;br /&gt;
===Type Conversion===&lt;br /&gt;
Some data types in Python can be converted from one type into another with certain methods. It&#039;s important to use the same type when using operations in Python. Only numeric data types can be used in mathematical operations. It is possible to convert a string into a number data type with type conversion.&lt;br /&gt;
&lt;br /&gt;
To convert from one type into another, use &amp;lt;code&amp;gt;int()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;float()&amp;lt;/code&amp;gt; methods.&lt;br /&gt;
 x = 3 # int&lt;br /&gt;
 y = 2.9 # float&lt;br /&gt;
 z = &amp;quot;4&amp;quot; # string&lt;br /&gt;
 &lt;br /&gt;
 # convert from int to float:&lt;br /&gt;
 a = float(x)&lt;br /&gt;
 &lt;br /&gt;
 # convert from float to int:&lt;br /&gt;
 b = int(y)&lt;br /&gt;
 &lt;br /&gt;
 # convert from string to int:&lt;br /&gt;
 c = int(z)&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39154</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39154"/>
		<updated>2021-04-19T01:57:05Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Type Conversion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that variables can be thought of as &amp;quot;objects&amp;quot; or abstract data types representing various forms of information.&lt;br /&gt;
&lt;br /&gt;
===Declaring a Variable===&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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;
&lt;br /&gt;
It is possible to assign a new variable to a variable that has already been assigned as well. The new variable will store the information that the original variable was already assigned.&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
===Data Types===&lt;br /&gt;
&#039;&#039;&#039;Integer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
An integer is a whole number. It can be positive or negative but cannot contain any decimals. Integers have unlimited length.&lt;br /&gt;
&lt;br /&gt;
Examples of integers are:&lt;br /&gt;
 x = 1&lt;br /&gt;
 y = 3452374791834&lt;br /&gt;
 z = -289&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Float&#039;&#039;&#039;&lt;br /&gt;
A float, also known as a &amp;quot;floating point number,&amp;quot; is a number that contains one more decimals. A float can be either positive or negative.&lt;br /&gt;
&lt;br /&gt;
Examples of floats are:&lt;br /&gt;
 w = 24e4&lt;br /&gt;
 x = 10.2&lt;br /&gt;
 y = 1.0&lt;br /&gt;
 z = -23.9&lt;br /&gt;
&lt;br /&gt;
Note that a whole number can be made a float by adding a &amp;lt;code&amp;gt;.0&amp;lt;/code&amp;gt; at the end of the number. Floats can also be scientific numbers with an &amp;quot;e&amp;quot; to indicate a power of 10.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Complex&#039;&#039;&#039;&lt;br /&gt;
Complex numbers are numbers that be expressed in the form a + bi, where a and b are real numbers, and i is a symbol representing the imaginary unit. The imaginary unit satisfies the equation &amp;lt;math&amp;gt;i^2=-1&amp;lt;/math&amp;gt;. In python, complex numbers are written with a &amp;quot;j&amp;quot; as the imaginary part.&lt;br /&gt;
&lt;br /&gt;
Examples of complex numbers are:&lt;br /&gt;
 x = 3+5j&lt;br /&gt;
 y = 5j&lt;br /&gt;
 z = -8j&lt;br /&gt;
&lt;br /&gt;
===Type Conversion===&lt;br /&gt;
Some data types in Python can be converted from one type into another with certain methods. It&#039;s important to use the same type when using operations in Python. Only numeric data types can be used in mathematical operations. It is possible to convert a string into a number data type with type conversion.&lt;br /&gt;
&lt;br /&gt;
To convert from one type into another, use &amp;lt;code&amp;gt;int()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;float()&amp;lt;/code&amp;gt; methods.&lt;br /&gt;
 x = 3 # int&lt;br /&gt;
 y = 2.9 # float&lt;br /&gt;
 z = &amp;quot;4&amp;quot; # string&lt;br /&gt;
 &lt;br /&gt;
 # convert from int to float:&lt;br /&gt;
 a = float(x)&lt;br /&gt;
 &lt;br /&gt;
 # convert from float to int:&lt;br /&gt;
 b = int(y)&lt;br /&gt;
 &lt;br /&gt;
 # convert from string to int:&lt;br /&gt;
 c = int(z)&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39153</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39153"/>
		<updated>2021-04-19T01:56:46Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Type Conversion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that variables can be thought of as &amp;quot;objects&amp;quot; or abstract data types representing various forms of information.&lt;br /&gt;
&lt;br /&gt;
===Declaring a Variable===&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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;
&lt;br /&gt;
It is possible to assign a new variable to a variable that has already been assigned as well. The new variable will store the information that the original variable was already assigned.&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
===Data Types===&lt;br /&gt;
&#039;&#039;&#039;Integer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
An integer is a whole number. It can be positive or negative but cannot contain any decimals. Integers have unlimited length.&lt;br /&gt;
&lt;br /&gt;
Examples of integers are:&lt;br /&gt;
 x = 1&lt;br /&gt;
 y = 3452374791834&lt;br /&gt;
 z = -289&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Float&#039;&#039;&#039;&lt;br /&gt;
A float, also known as a &amp;quot;floating point number,&amp;quot; is a number that contains one more decimals. A float can be either positive or negative.&lt;br /&gt;
&lt;br /&gt;
Examples of floats are:&lt;br /&gt;
 w = 24e4&lt;br /&gt;
 x = 10.2&lt;br /&gt;
 y = 1.0&lt;br /&gt;
 z = -23.9&lt;br /&gt;
&lt;br /&gt;
Note that a whole number can be made a float by adding a &amp;lt;code&amp;gt;.0&amp;lt;/code&amp;gt; at the end of the number. Floats can also be scientific numbers with an &amp;quot;e&amp;quot; to indicate a power of 10.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Complex&#039;&#039;&#039;&lt;br /&gt;
Complex numbers are numbers that be expressed in the form a + bi, where a and b are real numbers, and i is a symbol representing the imaginary unit. The imaginary unit satisfies the equation &amp;lt;math&amp;gt;i^2=-1&amp;lt;/math&amp;gt;. In python, complex numbers are written with a &amp;quot;j&amp;quot; as the imaginary part.&lt;br /&gt;
&lt;br /&gt;
Examples of complex numbers are:&lt;br /&gt;
 x = 3+5j&lt;br /&gt;
 y = 5j&lt;br /&gt;
 z = -8j&lt;br /&gt;
&lt;br /&gt;
===Type Conversion===&lt;br /&gt;
Some data types in Python can be converted from one type into another with certain methods. It&#039;s important to use the same type when using operations in Python. Only numeric data types can be used in mathematical operations. It is possible to convert a string into a number data type with type conversion.&lt;br /&gt;
&lt;br /&gt;
To convert from one type into another, use &amp;lt;code&amp;gt;int()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;float()&amp;lt;/code&amp;gt; methods.&lt;br /&gt;
 x = 3 # int&lt;br /&gt;
 y = 2.9 # float&lt;br /&gt;
 z = &amp;quot;4&amp;quot; # string&lt;br /&gt;
 # convert from int to float:&lt;br /&gt;
 a = float(x)&lt;br /&gt;
 # convert from float to int:&lt;br /&gt;
 b = int(y)&lt;br /&gt;
 # convert from string to int:&lt;br /&gt;
 c = int(z)&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39152</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39152"/>
		<updated>2021-04-19T01:55:59Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Type Conversion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that variables can be thought of as &amp;quot;objects&amp;quot; or abstract data types representing various forms of information.&lt;br /&gt;
&lt;br /&gt;
===Declaring a Variable===&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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;
&lt;br /&gt;
It is possible to assign a new variable to a variable that has already been assigned as well. The new variable will store the information that the original variable was already assigned.&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
===Data Types===&lt;br /&gt;
&#039;&#039;&#039;Integer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
An integer is a whole number. It can be positive or negative but cannot contain any decimals. Integers have unlimited length.&lt;br /&gt;
&lt;br /&gt;
Examples of integers are:&lt;br /&gt;
 x = 1&lt;br /&gt;
 y = 3452374791834&lt;br /&gt;
 z = -289&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Float&#039;&#039;&#039;&lt;br /&gt;
A float, also known as a &amp;quot;floating point number,&amp;quot; is a number that contains one more decimals. A float can be either positive or negative.&lt;br /&gt;
&lt;br /&gt;
Examples of floats are:&lt;br /&gt;
 w = 24e4&lt;br /&gt;
 x = 10.2&lt;br /&gt;
 y = 1.0&lt;br /&gt;
 z = -23.9&lt;br /&gt;
&lt;br /&gt;
Note that a whole number can be made a float by adding a &amp;lt;code&amp;gt;.0&amp;lt;/code&amp;gt; at the end of the number. Floats can also be scientific numbers with an &amp;quot;e&amp;quot; to indicate a power of 10.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Complex&#039;&#039;&#039;&lt;br /&gt;
Complex numbers are numbers that be expressed in the form a + bi, where a and b are real numbers, and i is a symbol representing the imaginary unit. The imaginary unit satisfies the equation &amp;lt;math&amp;gt;i^2=-1&amp;lt;/math&amp;gt;. In python, complex numbers are written with a &amp;quot;j&amp;quot; as the imaginary part.&lt;br /&gt;
&lt;br /&gt;
Examples of complex numbers are:&lt;br /&gt;
 x = 3+5j&lt;br /&gt;
 y = 5j&lt;br /&gt;
 z = -8j&lt;br /&gt;
&lt;br /&gt;
===Type Conversion===&lt;br /&gt;
Some data types in Python can be converted from one type into another with certain methods. It&#039;s important to use the same type when using operations in Python. Only numeric data types can be used in mathematical operations. It is possible to convert a string into a number data type with type conversion.&lt;br /&gt;
&lt;br /&gt;
To convert from one type into another, use &amp;lt;code&amp;gt;int()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;float()&amp;lt;/code&amp;gt; methods.&lt;br /&gt;
 x = 3 # int&lt;br /&gt;
 y = 2.9 # float&lt;br /&gt;
 z = &amp;quot;4&amp;quot; # string&lt;br /&gt;
&lt;br /&gt;
 # convert from int to float:&lt;br /&gt;
 a = float(x)&lt;br /&gt;
&lt;br /&gt;
 # convert from float to int:&lt;br /&gt;
 b = int(y)&lt;br /&gt;
&lt;br /&gt;
 # convert from string to int:&lt;br /&gt;
 c = int(z)&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39151</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39151"/>
		<updated>2021-04-19T01:53:29Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Data Types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that variables can be thought of as &amp;quot;objects&amp;quot; or abstract data types representing various forms of information.&lt;br /&gt;
&lt;br /&gt;
===Declaring a Variable===&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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;
&lt;br /&gt;
It is possible to assign a new variable to a variable that has already been assigned as well. The new variable will store the information that the original variable was already assigned.&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
===Data Types===&lt;br /&gt;
&#039;&#039;&#039;Integer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
An integer is a whole number. It can be positive or negative but cannot contain any decimals. Integers have unlimited length.&lt;br /&gt;
&lt;br /&gt;
Examples of integers are:&lt;br /&gt;
 x = 1&lt;br /&gt;
 y = 3452374791834&lt;br /&gt;
 z = -289&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Float&#039;&#039;&#039;&lt;br /&gt;
A float, also known as a &amp;quot;floating point number,&amp;quot; is a number that contains one more decimals. A float can be either positive or negative.&lt;br /&gt;
&lt;br /&gt;
Examples of floats are:&lt;br /&gt;
 w = 24e4&lt;br /&gt;
 x = 10.2&lt;br /&gt;
 y = 1.0&lt;br /&gt;
 z = -23.9&lt;br /&gt;
&lt;br /&gt;
Note that a whole number can be made a float by adding a &amp;lt;code&amp;gt;.0&amp;lt;/code&amp;gt; at the end of the number. Floats can also be scientific numbers with an &amp;quot;e&amp;quot; to indicate a power of 10.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Complex&#039;&#039;&#039;&lt;br /&gt;
Complex numbers are numbers that be expressed in the form a + bi, where a and b are real numbers, and i is a symbol representing the imaginary unit. The imaginary unit satisfies the equation &amp;lt;math&amp;gt;i^2=-1&amp;lt;/math&amp;gt;. In python, complex numbers are written with a &amp;quot;j&amp;quot; as the imaginary part.&lt;br /&gt;
&lt;br /&gt;
Examples of complex numbers are:&lt;br /&gt;
 x = 3+5j&lt;br /&gt;
 y = 5j&lt;br /&gt;
 z = -8j&lt;br /&gt;
&lt;br /&gt;
===Type Conversion===&lt;br /&gt;
Some data types in Python can be converted from one type into another with certain methods.&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39150</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39150"/>
		<updated>2021-04-19T01:52:52Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that variables can be thought of as &amp;quot;objects&amp;quot; or abstract data types representing various forms of information.&lt;br /&gt;
&lt;br /&gt;
===Declaring a Variable===&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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;
&lt;br /&gt;
It is possible to assign a new variable to a variable that has already been assigned as well. The new variable will store the information that the original variable was already assigned.&lt;br /&gt;
&lt;br /&gt;
 x = 7&lt;br /&gt;
 reassigned_variable = x  # Final value is 7, because x is 7&lt;br /&gt;
&lt;br /&gt;
===Data Types===&lt;br /&gt;
&#039;&#039;&#039;Integer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
An integer is a whole number. It can be positive or negative but cannot contain any decimals. Integers have unlimited length.&lt;br /&gt;
&lt;br /&gt;
Examples of integers are:&lt;br /&gt;
 x = 1&lt;br /&gt;
 y = 3452374791834&lt;br /&gt;
 z = -289&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Float&#039;&#039;&#039;&lt;br /&gt;
A float, also known as a &amp;quot;floating point number,&amp;quot; is a number that contains one more decimals. A float can be either positive or negative.&lt;br /&gt;
&lt;br /&gt;
Examples of floats are:&lt;br /&gt;
 w = 24e4&lt;br /&gt;
 x = 10.2&lt;br /&gt;
 y = 1.0&lt;br /&gt;
 z = -23.9&lt;br /&gt;
&lt;br /&gt;
Note that a whole number can be made a float by adding a &amp;lt;code&amp;gt;.0&amp;lt;/code&amp;gt; at the end of the number. Floats can also be scientific numbers with an &amp;quot;e&amp;quot; to indicate a power of 10.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Complex&#039;&#039;&#039;&lt;br /&gt;
Complex numbers are numbers that be expressed in the form a + bi, where a and b are real numbers, and i is a symbol representing the imaginary unit. The imaginary unit satisfies the equation &amp;lt;math&amp;gt;i^2=-1&amp;lt;/math&amp;gt;. In python, complex numbers are written with a &amp;quot;j&amp;quot; as the imaginary part.&lt;br /&gt;
&lt;br /&gt;
Examples of complex numbers are:&lt;br /&gt;
 x = 3+5j&lt;br /&gt;
 y = 5j&lt;br /&gt;
 z = -8j&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39149</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39149"/>
		<updated>2021-04-19T01:47:08Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Data Types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that variables can be thought of as &amp;quot;objects&amp;quot; or abstract data types representing various forms of information.&lt;br /&gt;
&lt;br /&gt;
===Data Types===&lt;br /&gt;
&#039;&#039;&#039;Integer&#039;&#039;&#039;&lt;br /&gt;
An integer is a whole number. It can be positive or negative but cannot contain any decimals. Integers have unlimited length.&lt;br /&gt;
&lt;br /&gt;
Examples of integers are:&lt;br /&gt;
 x = 1&lt;br /&gt;
 y = 3452374791834&lt;br /&gt;
 z = -289&lt;br /&gt;
&lt;br /&gt;
===Declaring a Variable===&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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;
&lt;br /&gt;
It is possible to assign a new variable to a variable that has already been assigned as well. The new variable will store the information that the original variable was already assigned.&lt;br /&gt;
&lt;br /&gt;
 x = 7&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39148</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39148"/>
		<updated>2021-04-19T01:45:47Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that variables can be thought of as &amp;quot;objects&amp;quot; or abstract data types representing various forms of information.&lt;br /&gt;
&lt;br /&gt;
===Data Types===&lt;br /&gt;
&#039;&#039;&#039;Type: Integer&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Declaring a Variable===&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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;
&lt;br /&gt;
It is possible to assign a new variable to a variable that has already been assigned as well. The new variable will store the information that the original variable was already assigned.&lt;br /&gt;
&lt;br /&gt;
 x = 7&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39147</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39147"/>
		<updated>2021-04-19T01:44:52Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Python Basics */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that variables can be thought of as &amp;quot;objects&amp;quot; or abstract data types representing various forms of information.&lt;br /&gt;
&lt;br /&gt;
===Data Types===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Declaring a Variable===&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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;
&lt;br /&gt;
It is possible to assign a new variable to a variable that has already been assigned as well. The new variable will store the information that the original variable was already assigned.&lt;br /&gt;
&lt;br /&gt;
 x = 7&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39146</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39146"/>
		<updated>2021-04-19T01:44:15Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that variables can be thought of as &amp;quot;objects&amp;quot; or abstract data types representing various forms of information.&lt;br /&gt;
&lt;br /&gt;
==Declaring a Variable==&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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;
&lt;br /&gt;
It is possible to assign a new variable to a variable that has already been assigned as well. The new variable will store the information that the original variable was already assigned.&lt;br /&gt;
&lt;br /&gt;
 x = 7&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39145</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39145"/>
		<updated>2021-04-19T01:43:11Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Python Basics */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that 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 data 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;
==Declaring a Variable==&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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;
&lt;br /&gt;
It is possible to assign a new variable to a variable that has already been assigned as well. The new variable will store the information that the original variable was already assigned.&lt;br /&gt;
&lt;br /&gt;
 x = 7&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39144</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39144"/>
		<updated>2021-04-19T01:39:35Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Python Basics */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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. The variables are only stored 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 means that 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;
==Declaring a Variable==&lt;br /&gt;
Python has no specific command for declaring a variable. Instead, a variable is created the moment a user assigns a value to it. 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. It&#039;s important to note that the underscore is generally reserved for library variables, so it is best to stick with letters. It also 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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39143</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39143"/>
		<updated>2021-04-19T01:37:00Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Python Basics */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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;
==Syntax==&lt;br /&gt;
One of the most important components of Python syntax is indentation. Indentation refers to the spaces at the beginning of a line of code, which can also be achieved by using the tab button. While in some programming languages indentation is only used for aesthetic purposes, indentation is necessary for the functionality for code in Python. The number of spaces needed is up to you as the programmer, but it must be at least one. If the indentation is skipped, Python will give the user an error message, and the code will not be able to run. Indentation will come up later in loops such as if-loops and for-loops.&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 means that 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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39142</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39142"/>
		<updated>2021-04-19T01:34:18Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* The Main Idea */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
* Be used on a server to create web applications.&lt;br /&gt;
* Be used along software to create workflow.&lt;br /&gt;
* Connect to database systems to read and modify files.&lt;br /&gt;
* Handle big data and perform complex math operations.&lt;br /&gt;
* Be used for rapid prototyping, otherwise known as production-ready software development.&lt;br /&gt;
&lt;br /&gt;
Python is used over other languages for many various reasons. Its simple syntax allows developers to write programs with fewer lines than some other programming languages. It also runs on an interpreter system, allowing for code to be executed as soon as it is written.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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 means that 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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39141</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39141"/>
		<updated>2021-04-19T01:32:23Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* The Main Idea */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&lt;br /&gt;
&lt;br /&gt;
Python is primarily used for web development, software development, mathematics, and system scripting. Some more things python can do are:&lt;br /&gt;
&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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 means that 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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39140</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39140"/>
		<updated>2021-04-19T01:26:25Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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 means that 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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39139</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39139"/>
		<updated>2021-04-19T01:25:41Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Downloading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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.1] (as of February 2021).&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39138</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39138"/>
		<updated>2021-04-19T01:25:05Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: /* Versions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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. The most current version of Python found is Python 3.9.2, which was released on February 19, 2021.&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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39137</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39137"/>
		<updated>2021-04-19T01:24:09Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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. Python has a unique design through its emphasis of code readability by having a notable use of significant indentation.&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. It allows its users to create objects such as spheres and cones and displays these objects in another window. 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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39136</id>
		<title>Python Syntax</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=Python_Syntax&amp;diff=39136"/>
		<updated>2021-04-19T01:17:09Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#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>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=VPython_Object&amp;diff=39135</id>
		<title>VPython Object</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=VPython_Object&amp;diff=39135"/>
		<updated>2021-04-19T01:16:46Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A VPython Object is a representation of data in a specific in VPython both visually and numerically. Each object represents data through its attributes, specific characteristics assigned to each individual object. Objects play an essential role in the necessary knowledge for the coding portion of PHYS 2211 and 2212, as most of your programs will require the extensive usage and manipulation of objects. This page is intended to provide you a background on these objects, especially if you have no prior knowledge of coding or VPython.&lt;br /&gt;
&lt;br /&gt;
In this class, you should know how to create sphere objects and set their positions, and how to use arrows to show forces, fields, velocities, etc. &lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
Objects in VPython are intended to represent data in ways that can be easily visualized and understood by both the user and the computer. Each object has a type it belongs to, which determines its default attributes, as well as how the computer will choose to display it when the program runs. Objects must be uniquely named if you wish to refer to them again later in your program, and any graphical object you create (spheres, boxes, curves, arrows, etc.) continue to exist for as long as your program remains running - VPython will continue to display them regardless of where they are positioned. If you change an attribute of an object, such as its position or color, VPython will automatically display the object in its new location and/or with its new color.&lt;br /&gt;
&lt;br /&gt;
For example, let&#039;s say you create a sphere called &#039;ball&#039; - by default, ball has attributes pre-assigned to it, such as ball.pos (the .pos attribute signifies the position of the sphere) or ball.color (the .color attribute allows you to change the color of the sphere). Also, in addition to the preset attributes, you can also create new ones. Besides the position and radius, you can also create attributes for mass (ball.mass), velocity (ball.vel), momentum (ball.momentum), or anything else you see fit. Of course, not all attributes need to be added manually. They can be left blank and filled in with a default value which the program automatically assigns them &lt;br /&gt;
&lt;br /&gt;
==Basics==&lt;br /&gt;
To make an object and visualize it, it is required to import functions by writing following lines on the top of the code. If you are using Glowscript, these imports are not required.&lt;br /&gt;
&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import *&lt;br /&gt;
&lt;br /&gt;
Then, by writing following line on your code, you can instantiate &lt;br /&gt;
&lt;br /&gt;
 [variable name] = [object type]([attribute1].[attribute1 type], ... ,[attribute n].[attribute n type])&lt;br /&gt;
&lt;br /&gt;
For an object of type sphere, attributes might include position (pos), color, and size. You can also add attributes such as charge or material.&lt;br /&gt;
For an arrow, typical attributes are position (pos), the axis vector, and color.&lt;br /&gt;
&lt;br /&gt;
You can also change attributes of the certain objects after they have been created.&lt;br /&gt;
&lt;br /&gt;
 [variable name].[attribute] = [new attribute type]&lt;br /&gt;
&lt;br /&gt;
==Attributes==&lt;br /&gt;
Many objects in VPython carry common attributes regardless of their type. This section will cover the attributes you will be utilizing the most in this class. &lt;br /&gt;
&lt;br /&gt;
===Position===&lt;br /&gt;
The position attribute is common to almost every single object, and is probably the most important of the attributes. It determines the position of the object&#039;s center (in the case of spheres, boxes, etc.) or the object&#039;s endpoint (arrows, curves, etc.). It is of the vector type. To access and/or edit this attribute, it can be accessed using objectName.pos. Returning to the example from the above section, we can access the position of our sphere called &#039;ball&#039; by typing&lt;br /&gt;
&lt;br /&gt;
 ball.pos&lt;br /&gt;
&lt;br /&gt;
This would return the position of the ball in vector form, or allow you to refer to said position in calculations.&lt;br /&gt;
&lt;br /&gt;
In addition, because this is a vector, the position attribute has three components of its own, which can be accessed by typing:&lt;br /&gt;
&lt;br /&gt;
 ball.pos.x&lt;br /&gt;
 ball.pos.y&lt;br /&gt;
 ball.pos.z&lt;br /&gt;
&lt;br /&gt;
depending on the desired component of the position. The same rules apply as to ball.pos, however they are returned as single numbers instead of as a vector.&lt;br /&gt;
&lt;br /&gt;
To set the position of an object, one must first set the type of the object and then type pos([vector coordinates]). For instance, if we wanted to create an object called ball centered at (4,2,0), we would type&lt;br /&gt;
&lt;br /&gt;
 ball = objectType(pos(4,2,0))&lt;br /&gt;
&lt;br /&gt;
===Color===&lt;br /&gt;
The color attribute defines the object&#039;s color when it appears in the display window. This attribute is not important for data but more for display - it is simply to distinguish objects from one another, which is especially useful if you are working with a multitude of objects at once. &lt;br /&gt;
&lt;br /&gt;
Color can be assigned in one of two ways. The first way it can be assigned is through a preset color. The preset colors in VPython are blue, orange, green, red, purple, brown, pink, gray, olive, and cyan - any of these can be inserted to create the desired color. For instance, the syntax for creating a red color is:&lt;br /&gt;
&lt;br /&gt;
 color = color.red&lt;br /&gt;
 &lt;br /&gt;
Another way of assigning color is through an RGB vector, an additive form of assigning color. Red, green and blue layers are added together in various saturations and opacities to reproduce a broad array of colors. The vector contains three numbers from 0 to 255 - The first number represents the red, the second represents the green, and the third represents the blue. The higher the value of the number, the more it resembles that particular color. For instance, if we wanted to assign cyan to color, we would type&lt;br /&gt;
 color = (0, 255, 255)&lt;br /&gt;
&lt;br /&gt;
To set the color of an object, one must first set the type of the object and then set the color within the parentheses. For instance, if we wanted to create an object called ball which was cyan, we would type either&lt;br /&gt;
&lt;br /&gt;
 ball = objectType(color = color(cyan))&lt;br /&gt;
 ball = objectType(color = (0,255,255))&lt;br /&gt;
&lt;br /&gt;
===Axis===&lt;br /&gt;
The axis attribute is important specifically for arrows, as it determines the direction which the arrow points and how long it is. For instance, if you wanted to create an arrow parallel to the x-axis with a length of 5, the syntax could be:&lt;br /&gt;
&lt;br /&gt;
 myArrow = arrow(pos=vec(5, 0, 0), axis=vec(1, 1, 1), color=color.green)&lt;br /&gt;
&lt;br /&gt;
meaning the arrow points 5 units along the x axis and is perpendicular to the y and z axes. You will often use arrows to represent forces and fields, where the position will be the observation point, and the axis will the vector value of the force/field/etc.&lt;br /&gt;
&lt;br /&gt;
The axis attribute also determines orientation of other objects, such as rings or cylinders, but arrows are the only object whose size is specifically tied to the axis attribute.&lt;br /&gt;
&lt;br /&gt;
===Setting Attributes in a Loop===&lt;br /&gt;
Sometimes, the position vector will be given, and will be easy to set. In other cases, you may want to create, say 12 spheres in a circle, all a distance 2 from the origin. A quick way to do this is by by using a [http://physicsbook.gatech.edu/VPython_Loops loop] or a [http://physicsbook.gatech.edu/VPython_Lists list].&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
    i = 0&lt;br /&gt;
    while i &amp;lt; 2*pi:&lt;br /&gt;
        sphere(pos=vec(2*cos(i), 2*sin(i), 0), radius=0.5, color=color.green)&lt;br /&gt;
        i = i + 2*pi/12&lt;br /&gt;
&lt;br /&gt;
This would create 12 green spheres of radius .5 in a circle 2 units from the origin:&lt;br /&gt;
[[File:12circles.png|right]]&lt;br /&gt;
&lt;br /&gt;
===Material/Texture===&lt;br /&gt;
One of the main purposes of VPython programming is to help people&#039;s understanding on a physical principle or phenomenon by displaying an animation describing the principle or phenomenon. To achieve this, various objects are used in the program, and various attributes such as color and shape are used to distinguish them. Material is also one of that attributes, which does not change the essence of the phenomenon but helps people&#039;s understanding on the phenomenon.&lt;br /&gt;
&lt;br /&gt;
====Basic Materials====&lt;br /&gt;
&#039;&#039;&#039;Wood&#039;&#039;&#039;&lt;br /&gt;
 materials.wood&lt;br /&gt;
&lt;br /&gt;
 woodsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.wood)&lt;br /&gt;
 woodbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.wood)&lt;br /&gt;
&lt;br /&gt;
[[File:Wood.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Rough&#039;&#039;&#039;&lt;br /&gt;
 materials.rough&lt;br /&gt;
&lt;br /&gt;
 roughsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.rough)&lt;br /&gt;
 roughbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.rough)&lt;br /&gt;
&lt;br /&gt;
[[File:Rough.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Marble&#039;&#039;&lt;br /&gt;
 materials.marble&lt;br /&gt;
&lt;br /&gt;
 marblesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.marble)&lt;br /&gt;
 marblebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.marble)&lt;br /&gt;
&lt;br /&gt;
[[File:Marble.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Plastic&#039;&#039;&#039;&lt;br /&gt;
 materials.plastic&lt;br /&gt;
&lt;br /&gt;
 plasticsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.plastic)&lt;br /&gt;
 plasticbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.plastic)&lt;br /&gt;
&lt;br /&gt;
[[File:Plastic.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Earth&#039;&#039;&#039;&lt;br /&gt;
 materials.earth&lt;br /&gt;
&lt;br /&gt;
 earthsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.earth)&lt;br /&gt;
 earthbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.earth)&lt;br /&gt;
&lt;br /&gt;
[[File:Earth.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Diffuse&#039;&#039;&#039;&lt;br /&gt;
 materials.diffuse&lt;br /&gt;
&lt;br /&gt;
 diffusesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.diffuse)&lt;br /&gt;
 diffusebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.diffuse)&lt;br /&gt;
&lt;br /&gt;
[[File:Diffuse.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Emissive&#039;&#039;&#039;&lt;br /&gt;
Material which looks like it glows&lt;br /&gt;
&lt;br /&gt;
 materials.emissive&lt;br /&gt;
&lt;br /&gt;
 emissivesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.emissive)&lt;br /&gt;
 emissivebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.emissive)&lt;br /&gt;
&lt;br /&gt;
[[File:Emissive.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Unshaded&#039;&#039;&#039;&lt;br /&gt;
Material which does not affected by lighting&lt;br /&gt;
&lt;br /&gt;
 materials.unshaded&lt;br /&gt;
&lt;br /&gt;
 unshadedsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.unshaded)&lt;br /&gt;
 unshadedbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.unshaded)&lt;br /&gt;
&lt;br /&gt;
[[File:Unshaded.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shiny&#039;&#039;&#039;&lt;br /&gt;
 materials.shiny&lt;br /&gt;
&lt;br /&gt;
 shinysphere = sphere(pos = (-2,0,0), radius = 1, material = materials.shiny)&lt;br /&gt;
 shinybox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.shiny)&lt;br /&gt;
&lt;br /&gt;
[[File:Shiny.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chrome&#039;&#039;&#039;&lt;br /&gt;
 materials.chrome&lt;br /&gt;
&lt;br /&gt;
 chromesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.chrome)&lt;br /&gt;
 chromebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.chrome)&lt;br /&gt;
&lt;br /&gt;
[[File:Chrome.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Blazed&#039;&#039;&#039;&lt;br /&gt;
 materials.blazed&lt;br /&gt;
&lt;br /&gt;
 blazedsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.blazed)&lt;br /&gt;
 blazedbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.blazed)&lt;br /&gt;
&lt;br /&gt;
[[File:Blazed.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Silver&#039;&#039;&#039;&lt;br /&gt;
 materials.silver&lt;br /&gt;
&lt;br /&gt;
 silversphere = sphere(pos = (-2,0,0), radius = 1, material = materials.silver)&lt;br /&gt;
 silverbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.silver)&lt;br /&gt;
&lt;br /&gt;
[[File:Silver.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;BlueMarble&#039;&#039;&#039;&lt;br /&gt;
Earth with clouds&lt;br /&gt;
&lt;br /&gt;
 materials.BlueMarble&lt;br /&gt;
&lt;br /&gt;
 BlueMarblesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.BlueMarble)&lt;br /&gt;
 BlueMarblebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.BlueMarble)&lt;br /&gt;
&lt;br /&gt;
[[File:BlueMarble.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Bricks&#039;&#039;&#039;&lt;br /&gt;
 materials.bricks&lt;br /&gt;
&lt;br /&gt;
 brickssphere = sphere(pos = (-2,0,0), radius = 1, material = materials.bricks)&lt;br /&gt;
 bricksbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.bricks)&lt;br /&gt;
&lt;br /&gt;
[[File:Bricks.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Creating your own texture====&lt;br /&gt;
=====Making a text from a photo=====&lt;br /&gt;
&lt;br /&gt;
You can create a texture with a image file, using PIL, the Python Image Library.&lt;br /&gt;
To do this,PIL must be installed on the computer and the function &amp;quot;Image&amp;quot; should be imported.&lt;br /&gt;
&lt;br /&gt;
[http://www.pythonware.com/products/pil/#pil117]&lt;br /&gt;
&lt;br /&gt;
 from visual import *&lt;br /&gt;
 import Image # Must install PIL&lt;br /&gt;
&lt;br /&gt;
And the basic syntax is&lt;br /&gt;
&lt;br /&gt;
 name = &amp;quot;buzz&amp;quot;&lt;br /&gt;
 width = 64 # must be power of 2&lt;br /&gt;
 height = 64 # must be power of 2&lt;br /&gt;
 im = Image.open(name+&amp;quot;.jpg&amp;quot;)&lt;br /&gt;
 #print(im.size) # optionally, see size of image&lt;br /&gt;
 # Optional cropping:&lt;br /&gt;
 #im = im.crop((x1,y1,x2,y2)) # (0,0) is upper left&lt;br /&gt;
 im = im.resize((width,height), Image.ANTIALIAS)&lt;br /&gt;
 materials.saveTGA(name,im)&lt;br /&gt;
&lt;br /&gt;
You can use the texture &amp;quot;im&amp;quot;, which is created with an image file &amp;quot;buzz&amp;quot;, using following code&lt;br /&gt;
&lt;br /&gt;
 tex = materials.texture(data=im, mapping=&amp;quot;rectangular&amp;quot;) &lt;br /&gt;
 buzzbox = box(pos = (2,0,0), length=1, height=1, width=1, material = tex)&lt;br /&gt;
 buzzsphere = sphere(pos = (-2,0,0), radius = 1, material = tex)&lt;br /&gt;
&lt;br /&gt;
[[File:BuzzTexture.JPG]]&lt;br /&gt;
&lt;br /&gt;
===Other Attributes===&lt;br /&gt;
There are other attributes which are also important but not as essential (or common) as position/color/axis, such as radius and make_trail, among others. Most of these attributes are self-explanatory or will not be used in the course, so if you would like full descriptions of these attributes, refer to the [http://vpython.org/contents/docs/index.html VPython Documentation].&lt;br /&gt;
&lt;br /&gt;
==Common Objects==&lt;br /&gt;
In order to display and understand your code effectively, there are a certain few objects which will be essential, especially for this class.&lt;br /&gt;
&lt;br /&gt;
===Sphere===&lt;br /&gt;
[[File:Sphere.jpg|thumb|right|alt=Yellow Arrow|The example sphere]]&lt;br /&gt;
Spheres are the most basic but also very useful objects. A sphere object is a representation of a sphere with a set radius, position, and color. Spheres are commonly used to represent particles in assignments and labs, and are generally assigned a velocity / momentum / etc. in problems. Spheres generally have three properties which should be set when creating them - radius, position, and color, in any order within the parentheses. Only the position is required  -  note that the position attribute for a cylinder, arrow, cone, and pyramid corresponds to one end of the object, whereas for a sphere it corresponds to the center of the object. If a radius and color are not specified, VPython will set the radius to 1 and the color to the current foreground color.&lt;br /&gt;
&lt;br /&gt;
For instance, if we wanted to create a yellow sphere at the origin with a radius of ten, we would type&lt;br /&gt;
&lt;br /&gt;
 yellowSphere = sphere(radius = 10, pos = vector(0,0,0), color=color.yellow)&lt;br /&gt;
&lt;br /&gt;
===Arrow===&lt;br /&gt;
[[File:arrowW.png|thumb|right|alt=Yellow Arrow|The example arrow]]&lt;br /&gt;
Arrows are just as multipurpose as spheres, if not more so. In this class, arrows will be used to represent vector quantities visually. For instance, you can use arrows to show the velocity/acceleration/momentum of a particle, the electric field direction around a charged particle, etc. Arrow objects are created with a position which represents the starting point of the arrow - not the center - and an axis which represents the arrow&#039;s direction and length. Both the position and the length are vector quantities. The color is again not essential as VPython will set it to a default value if left out. The arrow object itself features a straight box-shaped shaft with a 3d pyramid-shaped arrowhead at one end.&lt;br /&gt;
&lt;br /&gt;
For instance, to create an white arrow based at (4,2,0) pointing in the direction of (-2,2,-4), we would type&lt;br /&gt;
&lt;br /&gt;
 nameArrow = arrow(pos=(4,2,0), axis=(-2,2,-4), color=color.white)&lt;br /&gt;
&lt;br /&gt;
===Box===&lt;br /&gt;
[[File:ArrowV.jpg|thumb|right|alt=Yellow Arrow|The example box]]&lt;br /&gt;
Boxes will feature more in Physics 1 during the kinematics and dynamics sections. While the position attribute is the center of the box as with a sphere, the other attributes of boxes are more complex than spheres or arrows, and particular heed must be paid to the axis attribute, as the box&#039;s rotation and orientation depends on it. The axis attribute sets the direction of the length of the box, assuming the length, width and height of the box are set before. If they are not given, the length is automatically set to the magnitude of the axis vector. &lt;br /&gt;
&lt;br /&gt;
To create a green cube with its corner at the origin and a side length of 5 (pictured), we would type&lt;br /&gt;
&lt;br /&gt;
 greenbox = box(pos=(2.5, 2.5, 2.5), length=5, height=5, width=5) &lt;br /&gt;
&lt;br /&gt;
The axis attribute can also be added to tilt the box by changing the angle of the length. For example, this would cause the box from the previous step to be tipped at a 45 degree angle:&lt;br /&gt;
&lt;br /&gt;
 tippedbox = box(pos=(2.5, 2.5, 2.5), axis(1,1,0), length=5, height=5, width=5)&lt;br /&gt;
&lt;br /&gt;
The box can also be rotated around its own axis by changing which way is &amp;quot;up&amp;quot; for the box, by specifying an up attribute for the box that is different from the up vector of the coordinate system. For instance, this would take the tipped box from the previous step and rotate it so that the top face of the box is perpendicular to the vector in question.&lt;br /&gt;
&lt;br /&gt;
 rotatedbox = box(pos=(2.5, 2.5, 2.5), axis(1,1,0), length=5, height=5, width=5, up=(2, 3, 1))&lt;br /&gt;
&lt;br /&gt;
===Cylinder===&lt;br /&gt;
[[File:Cyl.jpg|thumb|right|alt=Yellow Arrow|The example cylinder]]&lt;br /&gt;
Cylinders are useful wherever a rod comes into play. For instance, in Physics 2, you may see problems regarding charged rods or something of the sort. The cylinder&#039;s attributes are a bit different and incorporate elements of most of the other shapes. As such, knowing cylinder syntax gives you a good basis for any object you need to create. The position vector determines the center of the cylinder&#039;s base (similar to a cone&#039;s pos attribute) and not the center of the object, while the axis determines the direction and length of the cylinder (similar to the arrow&#039;s axis attribute). The radius is self-explanatory.&lt;br /&gt;
&lt;br /&gt;
For example, to make a red cylinder with the base centered at (4,1,3) which is 6 units tall, has a radius of 2, and is laying parallel to the x-axis, you would type&lt;br /&gt;
&lt;br /&gt;
 cyl = cylinder(pos=(4,1,3), axis=(6,0,0), radius=2, color=color.red)&lt;br /&gt;
&lt;br /&gt;
===Other===&lt;br /&gt;
Aside from the four main objects listed above, there are many more objects which can be used in your programs. You will not need the majority of them for this class, but they do exist, and you may want to learn about them and their attributes. Visit the VPython Documentation for more information on the following objects:&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:EllipseB.jpg|thumb|center|alt=Yellow Arrow|Ellipse]]&lt;br /&gt;
| [[File:RingB.jpg|thumb|center|alt=Yellow Arrow|Ring]]&lt;br /&gt;
| [[File:PyramidG.jpg|thumb|center|alt=Yellow Arrow|Pyramid]]&lt;br /&gt;
| [[File:HelixO.jpg|thumb|center|alt=Yellow Arrow|Helix]]&lt;br /&gt;
| [[File:FacesR.jpg|thumb|center|alt=Yellow Arrow|Face]]&lt;br /&gt;
| [[File:Curve.jpg|thumb|center|alt=Yellow Arrow|Curve]]&lt;br /&gt;
| [[File:ConeB.jpg|thumb|center|alt=Yellow Arrow|Cone]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===Simple===&lt;br /&gt;
Create a green sphere named &amp;quot;greenSphere&amp;quot; with a radius of 5 located at the origin. &lt;br /&gt;
&lt;br /&gt;
{| role=&amp;quot;presentation&amp;quot; class=&amp;quot;wikitable mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
| &amp;lt;strong&amp;gt;Solution&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;greenSphere = sphere(radius=5, pos=vector(0,0,0), color=color.green)&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Middling===&lt;br /&gt;
Create two objects. &lt;br /&gt;
* Object 1: A magenta sphere of radius 3 named sphereOne at the position (9,0,8)&lt;br /&gt;
* Object 2: A cyan arrow named arrowTwo that points from the origin to the center of sphereOne.&lt;br /&gt;
&lt;br /&gt;
{| role=&amp;quot;presentation&amp;quot; class=&amp;quot;wikitable mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
| &amp;lt;strong&amp;gt;Solution&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;sphereOne = sphere(radius=3.5, pos=vector(9,0,8), color=color.magenta)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;position = vector(0,0,0)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;arrow(pos=position, axis=(sphereOne.pos - position), color = color.cyan)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | Note: the position vector is used in the second line, because arrowTwo.pos cannot be called yet. The arrow has yet to be created - it is created in line 3.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Difficult===&lt;br /&gt;
Create three objects. &lt;br /&gt;
* Object 1: Sphere, radius of 2, located at (-4,-3,8)&lt;br /&gt;
* Object 2: Sphere, radius of 1, located at (6,11,0)&lt;br /&gt;
* Object 3: Curve, starting at origin, moving to first sphere, then to second&lt;br /&gt;
&lt;br /&gt;
{| role=&amp;quot;presentation&amp;quot; class=&amp;quot;wikitable mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
| &amp;lt;strong&amp;gt;Solution&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;sphereOne = sphere(radius = 2, pos=vector(-4,-3,8))&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;sphereTwo = sphere(radius = 1, pos=vector(6,11,0))&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;curveOne = curve(color=color.red, pos = (0,0,0))&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;curveOne.append(sphereOne.pos)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;curveOne.append(sphereOne.pos)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Applying Texture&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:EarthandMoon.GIF]]&lt;br /&gt;
&lt;br /&gt;
Trinket Link&lt;br /&gt;
[https://trinket.io/glowscript/6ddb3d237e]&lt;br /&gt;
&lt;br /&gt;
VPython code&lt;br /&gt;
 &lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import *&lt;br /&gt;
 from visual.graph import *&lt;br /&gt;
 scene.width=1024&lt;br /&gt;
 scene.height=760&lt;br /&gt;
&lt;br /&gt;
 # CONSTANTS&lt;br /&gt;
 G = 6.7e-11&lt;br /&gt;
 mEarth = 6e24&lt;br /&gt;
 mcraft = 15000&lt;br /&gt;
 deltat = 60&lt;br /&gt;
 t = 0&lt;br /&gt;
 mMoon = 7e22&lt;br /&gt;
 scale = 800000&lt;br /&gt;
 c=2.99792e8&lt;br /&gt;
&lt;br /&gt;
 #OBJECTS AND INITIAL VALUES&lt;br /&gt;
 Earth = sphere(pos=vector(0,0,0), radius=15e6, material = materials.BlueMarble)&lt;br /&gt;
 # Add a radius for the spacecraft. It should be BIG, so it can be seen.&lt;br /&gt;
 craft = sphere(pos=vector(-60160000,-192000,0), radius=2e6, material = materials.marble)&lt;br /&gt;
 Moon =  sphere(pos=vector(4e8,0,0), radius=1.75e6, material = materials.marble)&lt;br /&gt;
 vcraft = vector(735,2849,0)&lt;br /&gt;
 pcraft = mcraft*vcraft&lt;br /&gt;
&lt;br /&gt;
 trail = curve(color=craft.color)    # This creates a trail for the spacecraft&lt;br /&gt;
 #scene.autoscale = 1000000                 # And this prevents zooming in or out&lt;br /&gt;
&lt;br /&gt;
 pscale = Earth.radius / mag(pcraft)&lt;br /&gt;
 fscale = Earth.radius/ ((G*mEarth*mcraft)/mag(craft.pos-Earth.pos)**2)&lt;br /&gt;
 dpscale = 500 * Earth.radius/mag(pcraft)&lt;br /&gt;
&lt;br /&gt;
 r_EarthMoon = Moon.pos - Earth.pos #Relative position vector from Earth to Moon&lt;br /&gt;
 r_EarthMoon_mag = mag(r_EarthMoon)&lt;br /&gt;
 F_EarthMoon_mag = (G*mcraft*mEarth)/(r_EarthMoon_mag**2)&lt;br /&gt;
 r_EarthMoon_hat = r_EarthMoon/r_EarthMoon_mag&lt;br /&gt;
&lt;br /&gt;
 Force_EarthMoon = (-r_EarthMoon_hat)*F_EarthMoon_mag #Force on Moon due to Earth&lt;br /&gt;
 pMoon = Force_EarthMoon / deltat&lt;br /&gt;
&lt;br /&gt;
 # CALCULATIONS&lt;br /&gt;
 print(&amp;quot;p=&amp;quot;,  pcraft)&lt;br /&gt;
 while t &amp;lt; (10e10):&lt;br /&gt;
    rate(500)   # This slows down the animation (runs faster with bigger number)&lt;br /&gt;
    rE =  craft.pos - Earth.pos&lt;br /&gt;
    rEmag = mag(rE)&lt;br /&gt;
    FEmag = (G*mcraft*mEarth)/(rEmag**2)&lt;br /&gt;
    rEhat = rE/rEmag&lt;br /&gt;
    FEnet = (-rEhat)*FEmag&lt;br /&gt;
&lt;br /&gt;
    rM =  craft.pos - Moon.pos&lt;br /&gt;
    rMmag = mag(rM)&lt;br /&gt;
    FMmag = (G*mcraft*mMoon)/(rMmag**2)&lt;br /&gt;
    rMhat = rM/rMmag&lt;br /&gt;
    FMnet = (-rMhat)*FMmag&lt;br /&gt;
    &lt;br /&gt;
    Fnet = FMnet+FEnet&lt;br /&gt;
&lt;br /&gt;
    pcraft_i = pcraft + vector(0,0,0)&lt;br /&gt;
    pcraft_ii = mag(pcraft_i)    &lt;br /&gt;
    pcraft = pcraft + ((Fnet)*deltat)&lt;br /&gt;
    pcraft_f = pcraft&lt;br /&gt;
    pcraft_ff = mag(pcraft)&lt;br /&gt;
    vavg = pcraft/mcraft&lt;br /&gt;
    speedcraft = mag(vavg)&lt;br /&gt;
    craft.pos = craft.pos + vavg*deltat&lt;br /&gt;
&lt;br /&gt;
    Fnet_tangent = ((pcraft_ff-pcraft_ii)/deltat)*(pcraft/mag(pcraft))*pscale&lt;br /&gt;
    Fnet_perp = Fnet - Fnet_tangent&lt;br /&gt;
&lt;br /&gt;
    r_EarthMoon = Moon.pos - Earth.pos #Relative position vector from Earth to Moon&lt;br /&gt;
    r_EarthMoon_mag = mag(r_EarthMoon)&lt;br /&gt;
    F_EarthMoon_mag = (G*mcraft*mEarth)/(r_EarthMoon_mag**2)&lt;br /&gt;
    r_EarthMoon_hat = r_EarthMoon/r_EarthMoon_mag&lt;br /&gt;
    &lt;br /&gt;
    r_craftMoon = Moon.pos - craft.pos#Relative position vector from spacecraft to Moon&lt;br /&gt;
    r_craftMoon_mag = mag(r_craftMoon)&lt;br /&gt;
    F_craftMoon_mag = (G*mcraft*mEarth)/(r_craftMoon_mag**2)&lt;br /&gt;
    r_craftMoon_hat = r_craftMoon/r_craftMoon_mag    &lt;br /&gt;
&lt;br /&gt;
    Force_EarthMoon = (-r_EarthMoon_hat)*F_EarthMoon_mag #Force on Moon due to Earth&lt;br /&gt;
    Force_craftMoon = (-r_craftMoon_hat)*F_craftMoon_mag#Force on Moon due to spacecraft&lt;br /&gt;
    Fnet_Moon = Force_EarthMoon + Force_craftMoon #Net force on Moon&lt;br /&gt;
&lt;br /&gt;
    momentum_Moon = pMoon + Fnet_Moon*deltat#Update momentum of Moon&lt;br /&gt;
    vavg_Moon = momentum_Moon/mMoon&lt;br /&gt;
    Moon.pos = Moon.pos + vavg_Moon * deltat #Update momentum of Moon&lt;br /&gt;
&lt;br /&gt;
    trail.append(pos=craft.pos)  &lt;br /&gt;
    t = t+deltat&lt;br /&gt;
    pcraft = pcraft_f&lt;br /&gt;
    deltap = pcraft - pcraft_i&lt;br /&gt;
&lt;br /&gt;
==Connectedness ==&lt;br /&gt;
How is this topic connected to something that you are interested in?&lt;br /&gt;
* I quite enjoy coding myself on my own time; I have taken a couple online classes outside of Tech on Java and a class here on MATLAB. However, Python and its variants are still far and away my favorite languages to code in, and the one I am most knowledgeable in. I believe the inclusion of VPython in the Physics curriculum is overall a benefit to us students as it allows us to both learn the physics and visualize them by creating the models we do in Labs on VPython.&lt;br /&gt;
  &lt;br /&gt;
How is it connected to your major?&lt;br /&gt;
* As a Business Admin major I&#039;ll be doing IT Management, which requires me to have an understanding of computer systems at the very least. While VPython may not be quite what I need in the future, it is still a good basis in learning the ins and outs of a major programming language long before I have to delve into serious CS training - plus it lets me keep my coding skills sharp!&lt;br /&gt;
&lt;br /&gt;
Is there an interesting industrial application?&lt;br /&gt;
* Of course! Whereas the simplicity of Python/VPython have made it effective to illustrate simple physics as we do, it&#039;s also powerful elsewhere. VPython is being used by some as a [https://www.youtube.com/watch?v=hK60VT0c8eI simulation tool for robotics] among other things, while Python itself is the backbone for thousands of industrial softwares and applications. In addition, agencies such as NASA use Python and VPython in their labs - I used both programs during my two separate internships at NASA Glenn Research Center in Cleveland, OH.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython VPython] - VPython&#039;s biography, if you will&lt;br /&gt;
&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_basics VPython Basics] - Especially if you&#039;re totally new to coding as a whole, this page will bolster your learning&lt;br /&gt;
 &lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_Functions VPython Functions] - Working with functions, assuming you understand the basics of coding&lt;br /&gt;
&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_Loops VPython Loops] - The next step in VPython code knowledge after functions - using loops&lt;br /&gt;
&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_Common_Errors_and_Troubleshooting VPython Troubleshooting] - Having problems? Check here!&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/contents/docs/index.html&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/contents/docs/color.html&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/contents/docs/primitives.html&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/contents/docs/materials.html&lt;br /&gt;
&lt;br /&gt;
http://guigui.developpez.com/cours/python/vpython/en/?page=object&lt;/div&gt;</summary>
		<author><name>Ewang328</name></author>
	</entry>
	<entry>
		<id>http://www.physicsbook.gatech.edu/index.php?title=VPython_Object&amp;diff=39134</id>
		<title>VPython Object</title>
		<link rel="alternate" type="text/html" href="http://www.physicsbook.gatech.edu/index.php?title=VPython_Object&amp;diff=39134"/>
		<updated>2021-04-19T01:14:11Z</updated>

		<summary type="html">&lt;p&gt;Ewang328: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Eddy Wang - Spring 2021&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
A VPython Object is a representation of data in a specific in VPython both visually and numerically. Each object represents data through its attributes, specific characteristics assigned to each individual object. Objects play an essential role in the necessary knowledge for the coding portion of PHYS 2211 and 2212, as most of your programs will require the extensive usage and manipulation of objects. This page is intended to provide you a background on these objects, especially if you have no prior knowledge of coding or VPython.&lt;br /&gt;
&lt;br /&gt;
In this class, you should know how to create sphere objects and set their positions, and how to use arrows to show forces, fields, velocities, etc. &lt;br /&gt;
&lt;br /&gt;
==The Main Idea==&lt;br /&gt;
&lt;br /&gt;
Objects in VPython are intended to represent data in ways that can be easily visualized and understood by both the user and the computer. Each object has a type it belongs to, which determines its default attributes, as well as how the computer will choose to display it when the program runs. Objects must be uniquely named if you wish to refer to them again later in your program, and any graphical object you create (spheres, boxes, curves, arrows, etc.) continue to exist for as long as your program remains running - VPython will continue to display them regardless of where they are positioned. If you change an attribute of an object, such as its position or color, VPython will automatically display the object in its new location and/or with its new color.&lt;br /&gt;
&lt;br /&gt;
For example, let&#039;s say you create a sphere called &#039;ball&#039; - by default, ball has attributes pre-assigned to it, such as ball.pos (the .pos attribute signifies the position of the sphere) or ball.color (the .color attribute allows you to change the color of the sphere). Also, in addition to the preset attributes, you can also create new ones. Besides the position and radius, you can also create attributes for mass (ball.mass), velocity (ball.vel), momentum (ball.momentum), or anything else you see fit. Of course, not all attributes need to be added manually. They can be left blank and filled in with a default value which the program automatically assigns them &lt;br /&gt;
&lt;br /&gt;
==Basics==&lt;br /&gt;
To make an object and visualize it, it is required to import functions by writing following lines on the top of the code. If you are using Glowscript, these imports are not required.&lt;br /&gt;
&lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import *&lt;br /&gt;
&lt;br /&gt;
Then, by writing following line on your code, you can instantiate &lt;br /&gt;
&lt;br /&gt;
 [variable name] = [object type]([attribute1].[attribute1 type], ... ,[attribute n].[attribute n type])&lt;br /&gt;
&lt;br /&gt;
For an object of type sphere, attributes might include position (pos), color, and size. You can also add attributes such as charge or material.&lt;br /&gt;
For an arrow, typical attributes are position (pos), the axis vector, and color.&lt;br /&gt;
&lt;br /&gt;
You can also change attributes of the certain objects after they have been created.&lt;br /&gt;
&lt;br /&gt;
 [variable name].[attribute] = [new attribute type]&lt;br /&gt;
&lt;br /&gt;
==Attributes==&lt;br /&gt;
Many objects in VPython carry common attributes regardless of their type. This section will cover the attributes you will be utilizing the most in this class. &lt;br /&gt;
&lt;br /&gt;
===Position===&lt;br /&gt;
The position attribute is common to almost every single object, and is probably the most important of the attributes. It determines the position of the object&#039;s center (in the case of spheres, boxes, etc.) or the object&#039;s endpoint (arrows, curves, etc.). It is of the vector type. To access and/or edit this attribute, it can be accessed using objectName.pos. Returning to the example from the above section, we can access the position of our sphere called &#039;ball&#039; by typing&lt;br /&gt;
&lt;br /&gt;
 ball.pos&lt;br /&gt;
&lt;br /&gt;
This would return the position of the ball in vector form, or allow you to refer to said position in calculations.&lt;br /&gt;
&lt;br /&gt;
In addition, because this is a vector, the position attribute has three components of its own, which can be accessed by typing:&lt;br /&gt;
&lt;br /&gt;
 ball.pos.x&lt;br /&gt;
 ball.pos.y&lt;br /&gt;
 ball.pos.z&lt;br /&gt;
&lt;br /&gt;
depending on the desired component of the position. The same rules apply as to ball.pos, however they are returned as single numbers instead of as a vector.&lt;br /&gt;
&lt;br /&gt;
To set the position of an object, one must first set the type of the object and then type pos([vector coordinates]). For instance, if we wanted to create an object called ball centered at (4,2,0), we would type&lt;br /&gt;
&lt;br /&gt;
 ball = objectType(pos(4,2,0))&lt;br /&gt;
&lt;br /&gt;
===Color===&lt;br /&gt;
The color attribute defines the object&#039;s color when it appears in the display window. This attribute is not important for data but more for display - it is simply to distinguish objects from one another, which is especially useful if you are working with a multitude of objects at once. &lt;br /&gt;
&lt;br /&gt;
Color can be assigned in one of two ways. The first way it can be assigned is through a preset color. The preset colors in VPython are blue, orange, green, red, purple, brown, pink, gray, olive, and cyan - any of these can be inserted to create the desired color. For instance, the syntax for creating a red color is:&lt;br /&gt;
&lt;br /&gt;
 color = color.red&lt;br /&gt;
 &lt;br /&gt;
Another way of assigning color is through an RGB vector, an additive form of assigning color. Red, green and blue layers are added together in various saturations and opacities to reproduce a broad array of colors. The vector contains three numbers from 0 to 255 - The first number represents the red, the second represents the green, and the third represents the blue. The higher the value of the number, the more it resembles that particular color. For instance, if we wanted to assign cyan to color, we would type&lt;br /&gt;
 color = (0, 255, 255)&lt;br /&gt;
&lt;br /&gt;
To set the color of an object, one must first set the type of the object and then set the color within the parentheses. For instance, if we wanted to create an object called ball which was cyan, we would type either&lt;br /&gt;
&lt;br /&gt;
 ball = objectType(color = color(cyan))&lt;br /&gt;
 ball = objectType(color = (0,255,255))&lt;br /&gt;
&lt;br /&gt;
===Axis===&lt;br /&gt;
The axis attribute is important specifically for arrows, as it determines the direction which the arrow points and how long it is. For instance, if you wanted to create an arrow parallel to the x-axis with a length of 5, the syntax could be:&lt;br /&gt;
&lt;br /&gt;
 myArrow = arrow(pos=vec(5, 0, 0), axis=vec(1, 1, 1), color=color.green)&lt;br /&gt;
&lt;br /&gt;
meaning the arrow points 5 units along the x axis and is perpendicular to the y and z axes. You will often use arrows to represent forces and fields, where the position will be the observation point, and the axis will the vector value of the force/field/etc.&lt;br /&gt;
&lt;br /&gt;
The axis attribute also determines orientation of other objects, such as rings or cylinders, but arrows are the only object whose size is specifically tied to the axis attribute.&lt;br /&gt;
&lt;br /&gt;
===Setting Attributes in a Loop===&lt;br /&gt;
Sometimes, the position vector will be given, and will be easy to set. In other cases, you may want to create, say 12 spheres in a circle, all a distance 2 from the origin. A quick way to do this is by by using a [http://physicsbook.gatech.edu/VPython_Loops loop] or a [http://physicsbook.gatech.edu/VPython_Lists list].&lt;br /&gt;
&lt;br /&gt;
For example: &lt;br /&gt;
&lt;br /&gt;
    i = 0&lt;br /&gt;
    while i &amp;lt; 2*pi:&lt;br /&gt;
        sphere(pos=vec(2*cos(i), 2*sin(i), 0), radius=0.5, color=color.green)&lt;br /&gt;
        i = i + 2*pi/12&lt;br /&gt;
&lt;br /&gt;
This would create 12 green spheres of radius .5 in a circle 2 units from the origin:&lt;br /&gt;
[[File:12circles.png|right]]&lt;br /&gt;
&lt;br /&gt;
===Material/Texture===&lt;br /&gt;
One of the main purposes of VPython programming is to help people&#039;s understanding on a physical principle or phenomenon by displaying an animation describing the principle or phenomenon. To achieve this, various objects are used in the program, and various attributes such as color and shape are used to distinguish them. Material is also one of that attributes, which does not change the essence of the phenomenon but helps people&#039;s understanding on the phenomenon.&lt;br /&gt;
&lt;br /&gt;
====Basic Materials====&lt;br /&gt;
&#039;&#039;&#039;Wood&#039;&#039;&#039;&lt;br /&gt;
 materials.wood&lt;br /&gt;
&lt;br /&gt;
 woodsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.wood)&lt;br /&gt;
 woodbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.wood)&lt;br /&gt;
&lt;br /&gt;
[[File:Wood.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Rough&#039;&#039;&#039;&lt;br /&gt;
 materials.rough&lt;br /&gt;
&lt;br /&gt;
 roughsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.rough)&lt;br /&gt;
 roughbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.rough)&lt;br /&gt;
&lt;br /&gt;
[[File:Rough.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Marble&#039;&#039;&lt;br /&gt;
 materials.marble&lt;br /&gt;
&lt;br /&gt;
 marblesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.marble)&lt;br /&gt;
 marblebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.marble)&lt;br /&gt;
&lt;br /&gt;
[[File:Marble.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Plastic&#039;&#039;&#039;&lt;br /&gt;
 materials.plastic&lt;br /&gt;
&lt;br /&gt;
 plasticsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.plastic)&lt;br /&gt;
 plasticbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.plastic)&lt;br /&gt;
&lt;br /&gt;
[[File:Plastic.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Earth&#039;&#039;&#039;&lt;br /&gt;
 materials.earth&lt;br /&gt;
&lt;br /&gt;
 earthsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.earth)&lt;br /&gt;
 earthbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.earth)&lt;br /&gt;
&lt;br /&gt;
[[File:Earth.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Diffuse&#039;&#039;&#039;&lt;br /&gt;
 materials.diffuse&lt;br /&gt;
&lt;br /&gt;
 diffusesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.diffuse)&lt;br /&gt;
 diffusebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.diffuse)&lt;br /&gt;
&lt;br /&gt;
[[File:Diffuse.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Emissive&#039;&#039;&#039;&lt;br /&gt;
Material which looks like it glows&lt;br /&gt;
&lt;br /&gt;
 materials.emissive&lt;br /&gt;
&lt;br /&gt;
 emissivesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.emissive)&lt;br /&gt;
 emissivebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.emissive)&lt;br /&gt;
&lt;br /&gt;
[[File:Emissive.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Unshaded&#039;&#039;&#039;&lt;br /&gt;
Material which does not affected by lighting&lt;br /&gt;
&lt;br /&gt;
 materials.unshaded&lt;br /&gt;
&lt;br /&gt;
 unshadedsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.unshaded)&lt;br /&gt;
 unshadedbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.unshaded)&lt;br /&gt;
&lt;br /&gt;
[[File:Unshaded.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shiny&#039;&#039;&#039;&lt;br /&gt;
 materials.shiny&lt;br /&gt;
&lt;br /&gt;
 shinysphere = sphere(pos = (-2,0,0), radius = 1, material = materials.shiny)&lt;br /&gt;
 shinybox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.shiny)&lt;br /&gt;
&lt;br /&gt;
[[File:Shiny.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Chrome&#039;&#039;&#039;&lt;br /&gt;
 materials.chrome&lt;br /&gt;
&lt;br /&gt;
 chromesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.chrome)&lt;br /&gt;
 chromebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.chrome)&lt;br /&gt;
&lt;br /&gt;
[[File:Chrome.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Blazed&#039;&#039;&#039;&lt;br /&gt;
 materials.blazed&lt;br /&gt;
&lt;br /&gt;
 blazedsphere = sphere(pos = (-2,0,0), radius = 1, material = materials.blazed)&lt;br /&gt;
 blazedbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.blazed)&lt;br /&gt;
&lt;br /&gt;
[[File:Blazed.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Silver&#039;&#039;&#039;&lt;br /&gt;
 materials.silver&lt;br /&gt;
&lt;br /&gt;
 silversphere = sphere(pos = (-2,0,0), radius = 1, material = materials.silver)&lt;br /&gt;
 silverbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.silver)&lt;br /&gt;
&lt;br /&gt;
[[File:Silver.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;BlueMarble&#039;&#039;&#039;&lt;br /&gt;
Earth with clouds&lt;br /&gt;
&lt;br /&gt;
 materials.BlueMarble&lt;br /&gt;
&lt;br /&gt;
 BlueMarblesphere = sphere(pos = (-2,0,0), radius = 1, material = materials.BlueMarble)&lt;br /&gt;
 BlueMarblebox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.BlueMarble)&lt;br /&gt;
&lt;br /&gt;
[[File:BlueMarble.JPG]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Bricks&#039;&#039;&#039;&lt;br /&gt;
 materials.bricks&lt;br /&gt;
&lt;br /&gt;
 brickssphere = sphere(pos = (-2,0,0), radius = 1, material = materials.bricks)&lt;br /&gt;
 bricksbox = box(pos = (2,0,0), length=1, height=1, width=1, material = materials.bricks)&lt;br /&gt;
&lt;br /&gt;
[[File:Bricks.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Creating your own texture====&lt;br /&gt;
=====Making a text from a photo=====&lt;br /&gt;
&lt;br /&gt;
You can create a texture with a image file, using PIL, the Python Image Library.&lt;br /&gt;
To do this,PIL must be installed on the computer and the function &amp;quot;Image&amp;quot; should be imported.&lt;br /&gt;
&lt;br /&gt;
[http://www.pythonware.com/products/pil/#pil117]&lt;br /&gt;
&lt;br /&gt;
 from visual import *&lt;br /&gt;
 import Image # Must install PIL&lt;br /&gt;
&lt;br /&gt;
And the basic syntax is&lt;br /&gt;
&lt;br /&gt;
 name = &amp;quot;buzz&amp;quot;&lt;br /&gt;
 width = 64 # must be power of 2&lt;br /&gt;
 height = 64 # must be power of 2&lt;br /&gt;
 im = Image.open(name+&amp;quot;.jpg&amp;quot;)&lt;br /&gt;
 #print(im.size) # optionally, see size of image&lt;br /&gt;
 # Optional cropping:&lt;br /&gt;
 #im = im.crop((x1,y1,x2,y2)) # (0,0) is upper left&lt;br /&gt;
 im = im.resize((width,height), Image.ANTIALIAS)&lt;br /&gt;
 materials.saveTGA(name,im)&lt;br /&gt;
&lt;br /&gt;
You can use the texture &amp;quot;im&amp;quot;, which is created with an image file &amp;quot;buzz&amp;quot;, using following code&lt;br /&gt;
&lt;br /&gt;
 tex = materials.texture(data=im, mapping=&amp;quot;rectangular&amp;quot;) &lt;br /&gt;
 buzzbox = box(pos = (2,0,0), length=1, height=1, width=1, material = tex)&lt;br /&gt;
 buzzsphere = sphere(pos = (-2,0,0), radius = 1, material = tex)&lt;br /&gt;
&lt;br /&gt;
[[File:BuzzTexture.JPG]]&lt;br /&gt;
&lt;br /&gt;
===Other Attributes===&lt;br /&gt;
There are other attributes which are also important but not as essential (or common) as position/color/axis, such as radius and make_trail, among others. Most of these attributes are self-explanatory or will not be used in the course, so if you would like full descriptions of these attributes, refer to the [http://vpython.org/contents/docs/index.html VPython Documentation].&lt;br /&gt;
&lt;br /&gt;
==Common Objects==&lt;br /&gt;
In order to display and understand your code effectively, there are a certain few objects which will be essential, especially for this class.&lt;br /&gt;
&lt;br /&gt;
===Sphere===&lt;br /&gt;
[[File:Sphere.jpg|thumb|right|alt=Yellow Arrow|The example sphere]]&lt;br /&gt;
Spheres are the most basic but also very useful objects. A sphere object is a representation of a sphere with a set radius, position, and color. Spheres are commonly used to represent particles in assignments and labs, and are generally assigned a velocity / momentum / etc. in problems. Spheres generally have three properties which should be set when creating them - radius, position, and color, in any order within the parentheses. Only the position is required  -  note that the position attribute for a cylinder, arrow, cone, and pyramid corresponds to one end of the object, whereas for a sphere it corresponds to the center of the object. If a radius and color are not specified, VPython will set the radius to 1 and the color to the current foreground color.&lt;br /&gt;
&lt;br /&gt;
For instance, if we wanted to create a yellow sphere at the origin with a radius of ten, we would type&lt;br /&gt;
&lt;br /&gt;
 yellowSphere = sphere(radius = 10, pos = vector(0,0,0), color=color.yellow)&lt;br /&gt;
&lt;br /&gt;
===Arrow===&lt;br /&gt;
[[File:arrowW.png|thumb|right|alt=Yellow Arrow|The example arrow]]&lt;br /&gt;
Arrows are just as multipurpose as spheres, if not more so. In this class, arrows will be used to represent vector quantities visually. For instance, you can use arrows to show the velocity/acceleration/momentum of a particle, the electric field direction around a charged particle, etc. Arrow objects are created with a position which represents the starting point of the arrow - not the center - and an axis which represents the arrow&#039;s direction and length. Both the position and the length are vector quantities. The color is again not essential as VPython will set it to a default value if left out. The arrow object itself features a straight box-shaped shaft with a 3d pyramid-shaped arrowhead at one end.&lt;br /&gt;
&lt;br /&gt;
For instance, to create an white arrow based at (4,2,0) pointing in the direction of (-2,2,-4), we would type&lt;br /&gt;
&lt;br /&gt;
 nameArrow = arrow(pos=(4,2,0), axis=(-2,2,-4), color=color.white)&lt;br /&gt;
&lt;br /&gt;
===Box===&lt;br /&gt;
[[File:ArrowV.jpg|thumb|right|alt=Yellow Arrow|The example box]]&lt;br /&gt;
Boxes will feature more in Physics 1 during the kinematics and dynamics sections. While the position attribute is the center of the box as with a sphere, the other attributes of boxes are more complex than spheres or arrows, and particular heed must be paid to the axis attribute, as the box&#039;s rotation and orientation depends on it. The axis attribute sets the direction of the length of the box, assuming the length, width and height of the box are set before. If they are not given, the length is automatically set to the magnitude of the axis vector. &lt;br /&gt;
&lt;br /&gt;
To create a green cube with its corner at the origin and a side length of 5 (pictured), we would type&lt;br /&gt;
&lt;br /&gt;
 greenbox = box(pos=(2.5, 2.5, 2.5), length=5, height=5, width=5) &lt;br /&gt;
&lt;br /&gt;
The axis attribute can also be added to tilt the box by changing the angle of the length. For example, this would cause the box from the previous step to be tipped at a 45 degree angle:&lt;br /&gt;
&lt;br /&gt;
 tippedbox = box(pos=(2.5, 2.5, 2.5), axis(1,1,0), length=5, height=5, width=5)&lt;br /&gt;
&lt;br /&gt;
The box can also be rotated around its own axis by changing which way is &amp;quot;up&amp;quot; for the box, by specifying an up attribute for the box that is different from the up vector of the coordinate system. For instance, this would take the tipped box from the previous step and rotate it so that the top face of the box is perpendicular to the vector in question.&lt;br /&gt;
&lt;br /&gt;
 rotatedbox = box(pos=(2.5, 2.5, 2.5), axis(1,1,0), length=5, height=5, width=5, up=(2, 3, 1))&lt;br /&gt;
&lt;br /&gt;
===Cylinder===&lt;br /&gt;
[[File:Cyl.jpg|thumb|right|alt=Yellow Arrow|The example cylinder]]&lt;br /&gt;
Cylinders are useful wherever a rod comes into play. For instance, in Physics 2, you may see problems regarding charged rods or something of the sort. The cylinder&#039;s attributes are a bit different and incorporate elements of most of the other shapes. As such, knowing cylinder syntax gives you a good basis for any object you need to create. The position vector determines the center of the cylinder&#039;s base (similar to a cone&#039;s pos attribute) and not the center of the object, while the axis determines the direction and length of the cylinder (similar to the arrow&#039;s axis attribute). The radius is self-explanatory.&lt;br /&gt;
&lt;br /&gt;
For example, to make a red cylinder with the base centered at (4,1,3) which is 6 units tall, has a radius of 2, and is laying parallel to the x-axis, you would type&lt;br /&gt;
&lt;br /&gt;
 cyl = cylinder(pos=(4,1,3), axis=(6,0,0), radius=2, color=color.red)&lt;br /&gt;
&lt;br /&gt;
===Other===&lt;br /&gt;
Aside from the four main objects listed above, there are many more objects which can be used in your programs. You will not need the majority of them for this class, but they do exist, and you may want to learn about them and their attributes. Visit the VPython Documentation for more information on the following objects:&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:EllipseB.jpg|thumb|center|alt=Yellow Arrow|Ellipse]]&lt;br /&gt;
| [[File:RingB.jpg|thumb|center|alt=Yellow Arrow|Ring]]&lt;br /&gt;
| [[File:PyramidG.jpg|thumb|center|alt=Yellow Arrow|Pyramid]]&lt;br /&gt;
| [[File:HelixO.jpg|thumb|center|alt=Yellow Arrow|Helix]]&lt;br /&gt;
| [[File:FacesR.jpg|thumb|center|alt=Yellow Arrow|Face]]&lt;br /&gt;
| [[File:Curve.jpg|thumb|center|alt=Yellow Arrow|Curve]]&lt;br /&gt;
| [[File:ConeB.jpg|thumb|center|alt=Yellow Arrow|Cone]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===Simple===&lt;br /&gt;
Create a green sphere named &amp;quot;greenSphere&amp;quot; with a radius of 5 located at the origin. &lt;br /&gt;
&lt;br /&gt;
{| role=&amp;quot;presentation&amp;quot; class=&amp;quot;wikitable mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
| &amp;lt;strong&amp;gt;Solution&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;greenSphere = sphere(radius=5, pos=vector(0,0,0), color=color.green)&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Middling===&lt;br /&gt;
Create two objects. &lt;br /&gt;
* Object 1: A magenta sphere of radius 3 named sphereOne at the position (9,0,8)&lt;br /&gt;
* Object 2: A cyan arrow named arrowTwo that points from the origin to the center of sphereOne.&lt;br /&gt;
&lt;br /&gt;
{| role=&amp;quot;presentation&amp;quot; class=&amp;quot;wikitable mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
| &amp;lt;strong&amp;gt;Solution&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;sphereOne = sphere(radius=3.5, pos=vector(9,0,8), color=color.magenta)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;position = vector(0,0,0)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;arrow(pos=position, axis=(sphereOne.pos - position), color = color.cyan)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | Note: the position vector is used in the second line, because arrowTwo.pos cannot be called yet. The arrow has yet to be created - it is created in line 3.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Difficult===&lt;br /&gt;
Create three objects. &lt;br /&gt;
* Object 1: Sphere, radius of 2, located at (-4,-3,8)&lt;br /&gt;
* Object 2: Sphere, radius of 1, located at (6,11,0)&lt;br /&gt;
* Object 3: Curve, starting at origin, moving to first sphere, then to second&lt;br /&gt;
&lt;br /&gt;
{| role=&amp;quot;presentation&amp;quot; class=&amp;quot;wikitable mw-collapsible mw-collapsed&amp;quot;&lt;br /&gt;
| &amp;lt;strong&amp;gt;Solution&amp;lt;/strong&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;sphereOne = sphere(radius = 2, pos=vector(-4,-3,8))&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;sphereTwo = sphere(radius = 1, pos=vector(6,11,0))&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;curveOne = curve(color=color.red, pos = (0,0,0))&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;curveOne.append(sphereOne.pos)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; | &amp;lt;code&amp;gt;curveOne.append(sphereOne.pos)&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Applying Texture&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:EarthandMoon.GIF]]&lt;br /&gt;
&lt;br /&gt;
Trinket Link&lt;br /&gt;
[https://trinket.io/glowscript/6ddb3d237e]&lt;br /&gt;
&lt;br /&gt;
VPython code&lt;br /&gt;
 &lt;br /&gt;
 from __future__ import division&lt;br /&gt;
 from visual import *&lt;br /&gt;
 from visual.graph import *&lt;br /&gt;
 scene.width=1024&lt;br /&gt;
 scene.height=760&lt;br /&gt;
&lt;br /&gt;
 # CONSTANTS&lt;br /&gt;
 G = 6.7e-11&lt;br /&gt;
 mEarth = 6e24&lt;br /&gt;
 mcraft = 15000&lt;br /&gt;
 deltat = 60&lt;br /&gt;
 t = 0&lt;br /&gt;
 mMoon = 7e22&lt;br /&gt;
 scale = 800000&lt;br /&gt;
 c=2.99792e8&lt;br /&gt;
&lt;br /&gt;
 #OBJECTS AND INITIAL VALUES&lt;br /&gt;
 Earth = sphere(pos=vector(0,0,0), radius=15e6, material = materials.BlueMarble)&lt;br /&gt;
 # Add a radius for the spacecraft. It should be BIG, so it can be seen.&lt;br /&gt;
 craft = sphere(pos=vector(-60160000,-192000,0), radius=2e6, material = materials.marble)&lt;br /&gt;
 Moon =  sphere(pos=vector(4e8,0,0), radius=1.75e6, material = materials.marble)&lt;br /&gt;
 vcraft = vector(735,2849,0)&lt;br /&gt;
 pcraft = mcraft*vcraft&lt;br /&gt;
&lt;br /&gt;
 trail = curve(color=craft.color)    # This creates a trail for the spacecraft&lt;br /&gt;
 #scene.autoscale = 1000000                 # And this prevents zooming in or out&lt;br /&gt;
&lt;br /&gt;
 pscale = Earth.radius / mag(pcraft)&lt;br /&gt;
 fscale = Earth.radius/ ((G*mEarth*mcraft)/mag(craft.pos-Earth.pos)**2)&lt;br /&gt;
 dpscale = 500 * Earth.radius/mag(pcraft)&lt;br /&gt;
&lt;br /&gt;
 r_EarthMoon = Moon.pos - Earth.pos #Relative position vector from Earth to Moon&lt;br /&gt;
 r_EarthMoon_mag = mag(r_EarthMoon)&lt;br /&gt;
 F_EarthMoon_mag = (G*mcraft*mEarth)/(r_EarthMoon_mag**2)&lt;br /&gt;
 r_EarthMoon_hat = r_EarthMoon/r_EarthMoon_mag&lt;br /&gt;
&lt;br /&gt;
 Force_EarthMoon = (-r_EarthMoon_hat)*F_EarthMoon_mag #Force on Moon due to Earth&lt;br /&gt;
 pMoon = Force_EarthMoon / deltat&lt;br /&gt;
&lt;br /&gt;
 # CALCULATIONS&lt;br /&gt;
 print(&amp;quot;p=&amp;quot;,  pcraft)&lt;br /&gt;
 while t &amp;lt; (10e10):&lt;br /&gt;
    rate(500)   # This slows down the animation (runs faster with bigger number)&lt;br /&gt;
    rE =  craft.pos - Earth.pos&lt;br /&gt;
    rEmag = mag(rE)&lt;br /&gt;
    FEmag = (G*mcraft*mEarth)/(rEmag**2)&lt;br /&gt;
    rEhat = rE/rEmag&lt;br /&gt;
    FEnet = (-rEhat)*FEmag&lt;br /&gt;
&lt;br /&gt;
    rM =  craft.pos - Moon.pos&lt;br /&gt;
    rMmag = mag(rM)&lt;br /&gt;
    FMmag = (G*mcraft*mMoon)/(rMmag**2)&lt;br /&gt;
    rMhat = rM/rMmag&lt;br /&gt;
    FMnet = (-rMhat)*FMmag&lt;br /&gt;
    &lt;br /&gt;
    Fnet = FMnet+FEnet&lt;br /&gt;
&lt;br /&gt;
    pcraft_i = pcraft + vector(0,0,0)&lt;br /&gt;
    pcraft_ii = mag(pcraft_i)    &lt;br /&gt;
    pcraft = pcraft + ((Fnet)*deltat)&lt;br /&gt;
    pcraft_f = pcraft&lt;br /&gt;
    pcraft_ff = mag(pcraft)&lt;br /&gt;
    vavg = pcraft/mcraft&lt;br /&gt;
    speedcraft = mag(vavg)&lt;br /&gt;
    craft.pos = craft.pos + vavg*deltat&lt;br /&gt;
&lt;br /&gt;
    Fnet_tangent = ((pcraft_ff-pcraft_ii)/deltat)*(pcraft/mag(pcraft))*pscale&lt;br /&gt;
    Fnet_perp = Fnet - Fnet_tangent&lt;br /&gt;
&lt;br /&gt;
    r_EarthMoon = Moon.pos - Earth.pos #Relative position vector from Earth to Moon&lt;br /&gt;
    r_EarthMoon_mag = mag(r_EarthMoon)&lt;br /&gt;
    F_EarthMoon_mag = (G*mcraft*mEarth)/(r_EarthMoon_mag**2)&lt;br /&gt;
    r_EarthMoon_hat = r_EarthMoon/r_EarthMoon_mag&lt;br /&gt;
    &lt;br /&gt;
    r_craftMoon = Moon.pos - craft.pos#Relative position vector from spacecraft to Moon&lt;br /&gt;
    r_craftMoon_mag = mag(r_craftMoon)&lt;br /&gt;
    F_craftMoon_mag = (G*mcraft*mEarth)/(r_craftMoon_mag**2)&lt;br /&gt;
    r_craftMoon_hat = r_craftMoon/r_craftMoon_mag    &lt;br /&gt;
&lt;br /&gt;
    Force_EarthMoon = (-r_EarthMoon_hat)*F_EarthMoon_mag #Force on Moon due to Earth&lt;br /&gt;
    Force_craftMoon = (-r_craftMoon_hat)*F_craftMoon_mag#Force on Moon due to spacecraft&lt;br /&gt;
    Fnet_Moon = Force_EarthMoon + Force_craftMoon #Net force on Moon&lt;br /&gt;
&lt;br /&gt;
    momentum_Moon = pMoon + Fnet_Moon*deltat#Update momentum of Moon&lt;br /&gt;
    vavg_Moon = momentum_Moon/mMoon&lt;br /&gt;
    Moon.pos = Moon.pos + vavg_Moon * deltat #Update momentum of Moon&lt;br /&gt;
&lt;br /&gt;
    trail.append(pos=craft.pos)  &lt;br /&gt;
    t = t+deltat&lt;br /&gt;
    pcraft = pcraft_f&lt;br /&gt;
    deltap = pcraft - pcraft_i&lt;br /&gt;
&lt;br /&gt;
==Connectedness ==&lt;br /&gt;
How is this topic connected to something that you are interested in?&lt;br /&gt;
* I quite enjoy coding myself on my own time; I have taken a couple online classes outside of Tech on Java and a class here on MATLAB. However, Python and its variants are still far and away my favorite languages to code in, and the one I am most knowledgeable in. I believe the inclusion of VPython in the Physics curriculum is overall a benefit to us students as it allows us to both learn the physics and visualize them by creating the models we do in Labs on VPython.&lt;br /&gt;
  &lt;br /&gt;
How is it connected to your major?&lt;br /&gt;
* As a Business Admin major I&#039;ll be doing IT Management, which requires me to have an understanding of computer systems at the very least. While VPython may not be quite what I need in the future, it is still a good basis in learning the ins and outs of a major programming language long before I have to delve into serious CS training - plus it lets me keep my coding skills sharp!&lt;br /&gt;
&lt;br /&gt;
Is there an interesting industrial application?&lt;br /&gt;
* Of course! Whereas the simplicity of Python/VPython have made it effective to illustrate simple physics as we do, it&#039;s also powerful elsewhere. VPython is being used by some as a [https://www.youtube.com/watch?v=hK60VT0c8eI simulation tool for robotics] among other things, while Python itself is the backbone for thousands of industrial softwares and applications. In addition, agencies such as NASA use Python and VPython in their labs - I used both programs during my two separate internships at NASA Glenn Research Center in Cleveland, OH.&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython VPython] - VPython&#039;s biography, if you will&lt;br /&gt;
&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_basics VPython Basics] - Especially if you&#039;re totally new to coding as a whole, this page will bolster your learning&lt;br /&gt;
 &lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_Functions VPython Functions] - Working with functions, assuming you understand the basics of coding&lt;br /&gt;
&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_Loops VPython Loops] - The next step in VPython code knowledge after functions - using loops&lt;br /&gt;
&lt;br /&gt;
[http://www.physicsbook.gatech.edu/VPython_Common_Errors_and_Troubleshooting VPython Troubleshooting] - Having problems? Check here!&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/contents/docs/index.html&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/contents/docs/color.html&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/contents/docs/primitives.html&lt;br /&gt;
&lt;br /&gt;
http://vpython.org/contents/docs/materials.html&lt;br /&gt;
&lt;br /&gt;
http://guigui.developpez.com/cours/python/vpython/en/?page=object&lt;/div&gt;</summary>
		<author><name>Ewang328</name></author>
	</entry>
</feed>