Python Exercise
Topic 1
Answer on the following:
i. Determine the area of circle with radius of 1.2 m.
ii. Display the reverse order for FirstName and LastName in one sentence.
iii. Test the user input value is within 100 to 1000.
iv. Calculate 10 user input value and give multiplication of all number.
v. Check this sentence and determine total number of vowel.
“UCSI University is a comprehensive university in Kuala Lumpur, Malaysia.”
vi. Given, x = 5. Display [Value of x is “5”]
vii. By using for loop, determine the total possible match of summations between X and
Y to give more than 50.
X = [10, 20, 20, 20]
Y = [10, 25, 30, 40]
Topic 2
Answer of the following:
i. Develop a function, to solve ( x + y 2)∗(x +3 y ) for x = 3 and y = 1.2. Display your
answer in 3 decimal point.
ii. Develop a function, convert the value from SI unit (mm, cm and m) to Imperial unit
(ft). Display for 1 mm, 1 cm and 1 m
iii. Develop a function, to solve Pythagoras theorem for given angle and adjacent.
Topic 3
Answer of the following:
i. By using numpy, create list of array in between 1 to 100 and display the odd number
from this array.
ii. Plot y versus x for a function of y=sin(x) from π ¿2 π . Display and test the program
whether point at coordinate (x=3, y=0.5) is on the graph.
iii. Display and test the program for AB and CD are orthogonal or not. Given:
A(1,2), B(4,6), C(3,8) and D(-3,6)
iv. The volume V of liquid in a hollow horizontal cylinder of radius r and length L is
related to the depth of the liquid h by
Develop a function to create a plot of volume versus depth. Test the program for r = 2
m and L = 5 m.
Case study
A simple force balance on a spherical particle reaching terminal velocity in a fluid is given by:
v t=
√ 4 g ( ρ p −ρ ) D p
3 CD ρ
where v t is the terminal velocity in m/s, g is the acceleration of gravity given by g = 9.80665
m/s2, ρD is the particles density in kg/m3, ρ is the fluid density in kg/m3, D p is the diameter of
the spherical particle in m and CD is a dimensionless drag coefficient. The drag coefficient on
a spherical particle at terminal velocity varies with the Reynolds number (Re) as follows:
24 For ℜ< 0.1
CD=
ℜ
24 For 0.1< ℜ< 1000
CD= ( 1+0.14 R e0.7 )
ℜ
C D =0.44 For 1 000< ℜ<350 000
C D =0.19−8× 10 / ℜ
4
For ℜ>350000
Where ℜ=D p v t /μ and µ is the viscosity in Pa·s or kg/m·s.
a) Calculate the terminal velocity for particle with ρ p =1800 kg/m3 and D p=0.208× 10
−3
m falling in water at T = 298.15 K. where ρ = 994.6 kg/m3 and µ = 8.931×10 kg/m·s.
b) Plot the terminal velocity for particle for Re number in between 100 to 5000.