Lab 1:Python Review - ChrisPerez13/CompPhys GitHub Wiki
#Goal
The goal of this lab is to review previous Python skills and add to them by learning other operations that will be used later in this course.
#Overview
We learned to use functions, conditionals, loops, lists, and plotting.
##Functions
def addone(x):
""" this function adds one to the input number """
x = x + 1
print(x)
##Conditionals
# Test whether or not 18/2 is the same as 36/4
eq1=18/2
eq2=36/4
if eq1==eq2:
print("Equation1= Equation2")
else:
print("Equation1 is less than Equation2"
##Loops+ Lists
myvals = np.arange(10)
print(myvals)
for v in myvals:
if v>5:
print(v)
for i in range(len(myvals)):
print(myvals[I])
#Graphs
The importance of knowing how to plot functions or equations would make it easy to visualize values rather than reading a list of numbers.
y=50
v=15
a=9.8
t=5.07
import matplotlib.pyplot as plt
time=np.linspace(0,5.07,100)
vt=50+15*time-((9.8*time**2)/(2))
plt.figure()
plt.plot(time,vt)