Home - FouadM0426/comp.physics-spring-2025 GitHub Wiki

Lab 1.

Goals

The goal of this lab was to help improve and understand the following concepts. Functions,lists,conditionals, markdowns, loops and Plotting, these concepts are the foundations to help build upon further code that will be used in the future. #overview Conditional statements are used to helps with items that would be repetitive by hand, or to create a variable that will continue to add onto itself examples

# Use a while loop to print out the even numbers from 0-10 (inclusive)
i = 0
while i in range(0,11,2):
  print(i)
  i +=2

totalsum = 0
while totalsum in range(0,100,3):
  print(totalsum)
  totalsum += number


# Test whether or not 18/2 is the same as 36/4
x=18/2
y=36/4
if x==y:
  print("they are equal")
else:
  print("man im slow at this")

#plotting on python, along with creating functions Creating functions and plotting functions the importance of these functions it allows us to allow variables to continuously change without having to reset or hard code the variables back into the code.This also allows graphs to be created for any set variable we set, allowing us to change the domain and range of the graph and the sizing allowing many customizations.

# Your code here
import matplotlib.pylab as plt
import numpy as np
theta= np.linspace(0,2*math.pi,100)
plt.figure()
plt.subplot(3,1,1)
plt.plot(theta, np.sin(theta),"bo", markersize= 4, alpha= .5)
plt.subplot(3,1,2)
plt.plot(theta, np.cos(theta), "k*");
plt.subplot(3,1,3)
plt.plot(theta, np.cos(theta), "k*");
plt.plot(theta,np.sin(theta), "bo")![]
![image](https://github.com/user-attachments/assets/535ac7e6-03c9-4ff0-910c-6eb502e93045)
import matplotlib.pyplot as plt
y = height(time)
plt.xlabel("Time(s)")
plt.xlabel("height(m)")
plt.title("position vs time")
plt.plot(time,y)
plt.show
![image](https://github.com/user-attachments/assets/daedc498-1e8e-47ee-bb32-7f270e46fbea)

#formatted printing This concept is the very foundations of python or in coding in general due to we use this to help print out variables, and based off the variables we can begin to limit how precise the variables become. examples

myratio = 10/3
print(f"{myratio:.2f}")

print(f"my ratio = {myratio:.2f}")

# print pi to 5 decimal places
print(f"pi is approximately equal to: {math.pi:.5f}")

#Lists Lists are a simple function of my python used to combine variables may they be strings or numbers into one variable. These can be appended from empty or even overwritten as the function, if needed

# Make a list of two lists. Add to the first ``sub" list the following words
# 'One'
# 'Two'
# 'Three'
#  and add to the second list
# 1
# 2
# 3

list =[]
list2 =[]
list.append("one")
list.append("two")
list.append("three")
list.append(list2)
list2.append(1)
list2.append(2)
list2.append(3)
print(list)