0% found this document useful (0 votes)
8 views2 pages

Test 1

The document outlines the structure and content of a test for Applied Computer Methods (ENEL2CM) scheduled for April 18, 2024, lasting one hour and thirty minutes. It consists of four questions, each with multiple sections covering topics such as Python variables, NumPy arrays, scientific computing libraries, and file handling in Python. The total score for the test is 100 points, with each question worth 25 points.

Uploaded by

owethuhandsome03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Test 1

The document outlines the structure and content of a test for Applied Computer Methods (ENEL2CM) scheduled for April 18, 2024, lasting one hour and thirty minutes. It consists of four questions, each with multiple sections covering topics such as Python variables, NumPy arrays, scientific computing libraries, and file handling in Python. The total score for the test is 100 points, with each question worth 25 points.

Uploaded by

owethuhandsome03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Test 1: Applied Computer Methods (ENEL2CM) Date: 18/04/2024

Instructions:

• You will have one hour and thirty minutes to complete the test from 08:50 – 10:20 AM
• This test consists of four questions.
• Each question has four sections, with each section worth 25% of the question's total points.
• The total test score is 100 points.

Question 1: (25 points)

A) Define the three primary types of variables in Python and provide an example for each.
(6 points)
B) What error does Python return when you attempt to add a string and a float? Provide an example to
support your answer. (6 points)
C) Explain strong typing in Python with a brief code example demonstrating type conversion. (6
points)
D) Write a Python function to calculate the area and circumference of a circle. It should take the
circle's radius as input. (7 points)

Question 2: (25 points)

A) Describe how to create a NumPy array in a Python. Give examples of creating a one-dimensional
and two-dimensional array. (6 points)
B) Explain the use of slicing in NumPy arrays with examples. Demonstrate how to:
Access elements from the second to the fourth in an array named sampleArray. (4 points)
Extract the first and third columns of a 2D array. (5 points)
C) How do you perform element-wise operations on NumPy arrays (addition, subtraction, etc.)?
Provide an example. (5 points)
D) Write a short function using NumPy to calculate the mean, standard deviation, and variance of a
dataset. (5 points)

Question 3: (25 points)

A) Name five important libraries in Python for scientific computing and describe their uses. (5
points)
B) How do you import specific functions from libraries in Python? Provide examples using the sqrt
function from math. (5 points)
C) Write a Python function to determine the flow regime (laminar or turbulent) of a fluid in a pipe.
The function should take the fluid density, velocity, pipe diameter, and viscosity as inputs.

• Calculate the Reynolds number (Re) using the formula:


Re = (density * velocity * diameter) / viscosity
• If Re < 2300, the flow is laminar.
• If Re >= 2300, the flow is turbulent.
• The function should return a string indicating the flow regime ('laminar' or 'turbulent') (10
points)

D) Use Matplotlib to create a scatter plot of vapor pressure vs. temperature using the provided
dataset: (5 points)

temperatures = [20, 30, 40, 50, 60]


vapor_pressures = [0.5, 1.2, 3.0, 7.2, 14.0]

Question 4: (25 points)


A) Write Python code to read the first 3 lines of a text file named "data.txt" and print them to the
console. (6 points)
B) Write Python code to append the line "New data point: 25" to an existing file named "results.txt".
(6 points)
C) Write a python code that read a file called “Experiments.csv” and provide descriptive statistics
(mean, median, standard deviation). (7 points)
D) Write a short function that safely calculates the quotient of two numbers (x/y) using a try-except
block to handle potential ZeroDivisionError and TypeError exceptions. (6 points)

You might also like