Lab 01 - Jay1337/computational_physics GitHub Wiki
Goal: For this lab we wanted to go through each of the different basics of Python coding so that we could familiarize ourselves with how to achieve certain tasks in coding. Topics we covered during this lab where we changed or finished code include Python syntax, marking down, formatted printing, loops, conditionals, functions, and basic plotting.
Overview: To start off we covered the topic of Python syntax where we were given a code and had to fix the syntax of the provided code so that it would print variables properly. Our issue seen in the code was the missing curly braces {} around the variables inside the string, which would allow the variables song and artist to be printed in the correct places.
Next off was the markdown section where understood how to use Markdown syntax for writing equations and other special formatting like bold or italics in Python notebooks. When writing an equation we found that you must have $$ in the beginning and end so python knows it is an equation.
We then move to formatted printing where we learned how to shorten our decimals or have our print statement state a certain statement and print a certain number of decimals with that statement. Here we controlled numbers and how they would be seen.
Next up we go to the lists section where we created lists so that we could understand not only how to make them, but also how to access specific elements in our list. We did so by using len() often to identify the sum of the list, and then when trying to print a specific word or number we typed the variable and then added [#] so that it addresses which word/number we are trying to find. The number in the [] will always start at 0 being the first number or word.
Next we worked with loops where we created while and for loops between ranges to print out specific numbers such as evens or odds through the range.
We then looked at conditionals and implemented conditional statements using if and else. We used it to identify the differences and be able to point out a specific difference between the equations.
In the function section we learned how to create a function using def, which is creating a function with a name of our choice and return so a value can be sent back to the function and provide the specific value. We can use our function with a while or for loop as well as an if statement.
Lastly we worked on how to do basic plotting where we plotted the acceleration of a ball vs. time in the air as well as velocity vs. time and Position vs. time. we used kinematic equations to figure out velocity, acceleration, and position and use plt.plot to plot the graph of acceleration vs. time. This section also helped in understanding how to label a graph as well as using plt.subplot which is (number of rows, number of columns, index) of the graph.