Individual means that you do it yourself. You won't learn to code if you don't struggle for yourself and write your own code. Remember that while you can discuss the general (algorithmic) way to solve a problem, you should not even be looking at anyone else's code or showing anyone else your code for an individual assignment. Ask an instructor if you are really stuck and having very specific code problems.
Review the Group Work guidelines on Cavas and/or ask an instructor if you have any questions.
Mathematical models that use complex equations are very common in scientific computing (there are some examples in the pre-activity). And conditional statements are very important for many programming tasks including checking inputs and solving equations.
Be sure to spell all function names correctly - misspelled functions will lose points (and often break anyway since no one is sure what to type to call it).
When you are asked to modify, that means copy and paste then modify the function in a new cell. Also when you run multiple test cases, make sure that the code is executed or function called in such a way that there are results shown for each test case.
If you prefer showing your earlier, scratch work as you figure out what you are doing, please be sure that you make a final, complete, correct last function in its own cell that you then call several times to test. In other words, separate your thought process/working versions from the final one (a comment that tells us which is the final version would be lovely).
Every function should have at least a docstring at the start that states generally what it does (see Lesson3 team if you need a reminder). Make other comments as necessary.
A. Define a function called quadratic
that solves the quadratic equation assuming the discriminant is positive. It should take three parameters (a, b, and c values) and prints two real roots according to Equation 2 from the pre-activity. (Notes: No conditional statements should be used in this function. It will be clear below why we choose to print rather than return the roots.)
B. Run quadratic
with your values for question 15 from the Lesson 4 in-class team notebook (the values are also below but make sure you go back to the pre-activity to find the correct equation).
Include the solution with units and an explanation as a markdown cell.
How much time does it take a car initially traveling at a velocity of 11 m/s (~25 mph) to go 400m while applying a constant acceleration of 6.0 m/s2
C. Modify your quadratic
function by adding an if-statement that checks the discriminant and prints a user-friendly message if there are no real roots. Otherwise, it should still solve for x and print the two roots.
minimum test cases
x2 + 2x − 8 = 0 [2 real roots]
−2x2 − 3x − 4 = 0 [from preactivity, no real roots]
D. Finally, modify your quadratic
function so it checks the discriminant and only solves the equation once and prints the signle root if there is only one root. It should solve the equation twice and print both roots if there are two. And, it should still print a message and not solve the equation at all if there are no real roots.
minimum test cases
x2 + 2x − 8 = 0 [2 real roots]
−2x2 − 3x − 4 = 0 [from preactivity, no real roots]
−4x2 + 12x − 9 [1 real root]
E. Most organisms have a temperature range in which they can survive, and a narrower temperature range nested within that broad range within which they grow optimally and thrive. Assume that we are working with an organism that can survive as long as the temperature is between 95°C and 105°C (not including 95°C and 105°C), but thrives between (and including) 97.5°C and 103°C.
Define a monitor
function that takes the current temperature as a single parameter and prints one of the warnings below when the temperature needs adjusting. Your function should print out the single, most appropriate message from the lsit below based on the temperature parameter using if-elif-else
statements.
Do not use five if-statements.
Test monitor
with the values below to make sure that it works! (you should also add more tests - make sure that each message is triggered at least once)
F. Write a function called is_even
that takes an integer as a parameter and returns the Boolean value True
if the parameter is an even number and False
if it is odd. (Hint: an operator we learned about this week will be helpful to determine if the number is divisible by two.) Again, this function should not print anything. Also be careful that you are returning a Boolean value (no quotes needed).
Test is_even
with at least 4 numbers (2 even, 2 odd).
G. Now write an is_odd
function so that it uses a call to is_even
to determine if its argument is an odd integer. Your code should call the is_even
function, rather than copying, pasting, and modifying the code from is_even
.
Test is_odd
with at least 4 numbers (2 even, 2 odd).
In [ ]: