Tutorial 7 Flashcards
if grade > threshold:
print(‘Grade is greater than the threshold mark’)
elif grade== threshold:
print(‘Grade is below the threshold mark’)
else:
print(‘Grade is equal to the threshold mark’)
Perform a series of checks to see if the grade is equal to, greater than, or less than the threshold mark.
grade= 30
threshold= 40
What is the Output?
A= 400 # mm2
F = -210000 # N
fy = 355 # N/mm2
fu 500 # N/mm2
f F / A
print(‘stress is’, f)
if abs(f) <= fy:
print ( ‘ Elastic’ )
else:
print (‘Plastic’)
if abs(f) > fu:
print(‘Beyond ultimate stress’)
Stress is -525.0
Plastic
Beyond Ultimate Stress
What is the Output?
R = [104.6, -23.7, 0.9, 58.8, 77.3]
total= 0
for Ri in R:
total += Ri
print(‘5um of numbers is’, total)
217.9
What does this show?
n = 17
ksum = 0
for i in range(n + 1):
ksum += i
formula= 0.5 * n * (n + 1)
print(‘Summation’, ksum)
print(‘Formula’, int(formula))
This shows that the sum of k (e.g 1+2+3+4….) is eqault to the formula 0.5n(n+1) for all values of n.
E.g
n = 17
sum of ki + ki+1 = 153
0.5n(n+1) = 153
What does this Script do?
M = [ ]
w = 5
for L in range(l, 21):
M.append(w * L * L / 8)
print(M)
The maximum bending moment M [kNm] at the mid-span of a simply-supported beam of length L [m], subjected to a uniformly distributed load w [kN/m] is M = wL^2/8. Create a list M , that has maximum bending moment values for beams of lengths 1 m to 20 m under a load of w=5 kN/m.
[0.625, 2.5, 5.625, 10.0, 15.625, 22.5, 30.625, 40.0, 50.625, 62.5, 75.625, 90.0, 105.625, 122.5, 140.625, 160.0, 180.625, 202.5, 225.625, 250.0]
from math import cos
from math import exp
from math import sqrt
y 1
a 1
w0 10
wl sqrt(w02 - y2)
ts [0, 0.3, 0.9, 1.6]
xt [exp(-y * t) * a * cos(wl * t) for t in ts]
print(xt)
A damped free oscillator displaces with an equation form of x(t) = e-rt * a * cos(w1 t - a), assuming that r = 1, a = 1, a = 0, w0 = 10 and w1 = sqrt( w^2 - y2) , What are the displacements at t =0, 0.3, 0.9 and 1.6?
[1.0, -0.7317495132569392, -0.3625046786289805, -0.1973834427146229]
What does this code do?
from math import factorial
def P(n, r):
“”” Number of permutations function.
Parameters
n : int #Number of objects.
r int #Number of objects taken.
Returns
int
Number of permutations.
return int(factorial(n) / factorial(n - r))
print(P(n=10, r=6))
Write a function for P that takes required arguments n and r, and returns the number of permutations as an
integer. Don’t forget a detailed docstring!
P(n, r) = (n!) / (n - r)!
151200
What does this code do?
def forward_difference(y, x, h=10**(-6)):
“”” Forward difference gradient approximation.
Parameters
y func
The function of interest.
x float
Location to evaluate gradient at.
h float
Small perturbation.
Returns
float
Value of the approximated gradient.
return (y(x + h) - y(x)) / h
dydx = forward_difference(y=sin, x=0.77, h=10**(-3))
print(dydx, cos(0.77))
Write a function that takes another function as a required argument, and calculates the gradient for given x, and
for small perturbation h. If h is not given, it should take a small default value of 1 o-6.
dy/dx = (y(x+h) - y(x)) / h
0.717562482368872, 0.7179106696109433