ΣνΜDr. Sharon's Math PlatformSyvara Learning
</>

Programming for Engineers

Introduction to Python programming using AI tools (GitHub Copilot) and VS Code. Covers Python basics through data visualization and a final interactive project.

Q1
Python: string indexing, slicing, and uppercase on "Hello World"
Given the string w = "Hello World", write Python code to: (a) Access the single character at index 6. (b) Extract the substring "World" using slicing. (c)…
Variables, Data Types, and Strings 🟢 Intro Free with account
Q2
Python has two common ways to insert variables into strings: the %-format style and…
Python has two common ways to insert variables into strings: the %-format style and f-strings. (a) Using %-format, write code that prints: "Gonzaga is an…
Variables, Data Types, and Strings 🟢 Intro 🔒 $2.99
Q3
Create a list my_list = [1, 2, 3] and a tuple my_tuple = (1, 2, 3).
Create a list my_list = [1, 2, 3] and a tuple my_tuple = (1, 2, 3). (a) Change the element at index 2 of my_list to 99. Print the result. (b) Try to change…
Variables, Data Types, and Strings 🟡 Intermediate 🔒 $2.99
Q4
NumPy: array shapes, np.arange vs np.linspace
Using NumPy: (a) Create the 1D array [1, 4, 3] and the 2D array [[1, 4, 3], [9, 2, 7]]. Print the .shape of each. (b) Use np.arange to create: [0.5, 1.0, 1.5,…
NumPy Arrays and Matrix Operations 🟢 Intro Free with account
Q5
NumPy: indexing, element-wise ops, transpose, and b @ d
Given: y = np.array([[1, 4, 3], [9, 2, 7]]) b = np.array([[1, 2], [3, 4]]) d = np.array([[3, 4], [5, 6]]) (a) Extract the first row of y. (b) Extract columns…
NumPy Arrays and Matrix Operations 🟡 Intermediate 🔒 $2.99
Q6
Python: function my_trig returning multiple values with docstring
Define a Python function my_trig(a, b) that returns three values: 1. out1 = sin(a) + cos(b) 2. out2 = sin(b) + cos(a) 3. A list [out1, out2] Include a…
Functions 🟢 Intro 🔒 $2.99
Q7
(a) Define a lambda function called square that takes one argument and returns its…
(a) Define a lambda function called square that takes one argument and returns its square. Test with inputs 2 and 5. (b) Write an equivalent named function…
Functions 🟢 Intro 🔒 $2.99
Q8
In Python, functions are first-class objects — they can be passed as arguments to other…
In Python, functions are first-class objects — they can be passed as arguments to other functions. Write a function my_fun_plus_one(f, x) that takes a…
Functions 🟡 Intermediate Free with account
Q9
Write a Python for loop that computes the sum of every integer from 1 to n.
Write a Python for loop that computes the sum of every integer from 1 to n. (a) Use the accumulator pattern. Verify: n=3 gives 6, n=10 gives 55. (b) Write the…
Loops and Control Flow 🟢 Intro 🔒 $2.99
Q10
(a) Given numbers = [2, 4, 5, 7, 8, 10, 13], use a for loop and an if statement to count…
(a) Given numbers = [2, 4, 5, 7, 8, 10, 13], use a for loop and an if statement to count how many numbers are even (divisible by 2). Print the count. (b)…
Loops and Control Flow 🟡 Intermediate 🔒 $2.99
Q11
Python: debug a loop summing a list with print tracing
The code below should compute the sum of [3, 7, 2, 9, 5] but returns the wrong answer: numbers = [3, 7, 2, 9, 5] total = 1 for num in numbers: total += num…
Error Handling and Debugging 🟢 Intro 🔒 $2.99
Q12
The code below should count numbers greater than 5 in [2, 4, 5, 7, 8, 10, 13] but has…
The code below should count numbers greater than 5 in [2, 4, 5, 7, 8, 10, 13] but has two bugs: numbers = [2, 4, 5, 7, 8, 10, 13] count = 1 for num in…
Error Handling and Debugging 🟡 Intermediate 🔒 $2.99
Q13
The function below should compute n! (n factorial) but always returns 0. This is a logic…
The function below should compute n! (n factorial) but always returns 0. This is a logic error — no exception is raised, but the output is wrong. def…
Error Handling and Debugging 🟡 Intermediate 🔒 $2.99
Q14
Python: try/except for TypeError and ValueError in comparisons
The code below raises a TypeError because it compares a string to an integer: x = "6" if x > 3: print("x is larger than 3") (a) Wrap it in a try/except block…
Error Handling and Debugging 🟡 Intermediate 🔒 $2.99
Q15
The function below checks if a string is a palindrome (same forward and backward,…
The function below checks if a string is a palindrome (same forward and backward, ignoring case and non-alphanumeric characters): def is_palindrome(s):…
Testing with Doctest 🟡 Intermediate 🔒 $2.99
Working…