Once again, I will allow you the OPTION of working with a partner today. I STRONGLY encourage you to use a partner, but I will not require this option. If you work with a partner, you should be working on one computer and following the rules of paired programming. Overall, I think it will be better for you to work with a partner, but it is up to you.
You have been working with functions all semester (print(), range(), len(), etc). However, it is often helpful to be able to write your own functions.
To get started, download the following file:
First, open the file and type your names in the Name field. Save the file.
Next, take a look at what is in the file. You will see that there are two sections of code. Section one defines the stubs for three functions that you will write this :
Section Two contains code that will test the functions that you will write during this lab. You should not modify the code in the section. You MAY feel free to read what it says and does. This screenshot below is just a small part of the file:
Once you get done reading the code load and run this file. You should see:
In other words, right now this code is full of errors. Well that isn't very surprising because the three functions don't have any code in them right now which means they return nothing (or more accurately, they return None). Your job is to write the body of the three methods so that when you run you program you see no errors at all.
[Q1] Where will you be writing your code in this lab?
[SIG1] Please show this to an instructor BEFORE moving on
Customer Request #1 (hydrocarbon from the midterm)
In your file locate the stub of the function called hydrocarbon(). This function should:
When you think you have this working, load and run lab09.py. If you see ANY messages that talk about hydrocarbon then you know you don't yet fit the requirements listed above. See what is wrong and fix your code. Keep trying until all hydrocarbon messages disappear.
[SIG2] Please show this to an instructor BEFORE moving on
Customer Request #2 (bmi from PA02 )
In your file locate the stub of the function called bmi(). This function should:
So that everyone gets the EXACT same results you should use 0.0254 as your height conversion factor and 0.453592 as your weight conversion factor.
Again, keep modifying and rerunning your code until you eliminate any messages that bmi does not work.
[SIG3] Please show this to an instructor BEFORE moving on
Customer Request #3 (New assignment )
The Collatz conjecture is an unsolved conjecture in mathematics named after Lothar Collatz, who first proposed it in 1937. The conjecture is also known as the 3n + 1 conjecture (because of it's formula) or the hailstone sequence (because of the way that the numbers bounce up and down like hail until they finally converge to 1).
The sequence works as follows:
The conjecture is that no matter what number you start with, you will always eventually reach 1. This has been demonstrated true for integers of approximately 10**16 in size but has never formally been proven to be true.
For example, consider starting with a value of 3
|Old Value||This is:||So the new value is:|
|3||odd||3*3 + 1 = 10|
|10||even||10/2 = 5|
|5||odd||3*5 + 1 = 16|
|16||even||16/2 = 8|
|8||even||8/2 = 4|
|4||even||4/2 = 2|
|2||even||2/2 = 1|
This has a length of 7. We must perform 7 operations before we finally reach 1.
In your file locate the stub of the function called collatzLength(). This function should:
Again, keep modifying and rerunning your code until you eliminate any messages that collatzLength does not work.
[SIG4] Please show this to an instructor BEFORE moving on
You will know that you have written your functions correctly if you see the following when you run your code:
This week I will again ask you to submit your code for electronic grading, using the eLearning submission system.
Follow the directions on the system to select the appropriate course and assignment and submit
Don't forget to hand in your answer sheet to the professor or TA before you leave!