For this topic I had to write a program that calculates somebody's Body Mass Index (BMI). The inputs are the person's height in centimetres and weight in kilograms. The output is their weight divided by their height in metres squared.
- $ python bmi.py
- Enter weight: 65
- Enter height: 180
- BMI is 20.06.
Fot this task I had to write a program that takes asks a user to input a string and outputs every second letter in reverse order.
- $ python secondstring.py
- Please enter a sentence: The quick brown fox jumps over the lazy dog.
- .o zletrv pu o wr cu h
In this weeks task I had to write a program that asks the user to input any positive integer and outputs the successive values of the following calculation. At each step calculate the next value by taking the current value and, if it is even, divide it by two, but if it is odd, multiply it by three and add one. Have the program end if the current value is one.
- $ python collatz.py
- Please enter a positive integer: 10
- 10 5 16 8 4 2 1
- https://snakify.org/en/lessons/if_then_else_conditions/
- https://stackoverflow.com/questions/26198131/check-if-input-is-positive-integer
- https://github.com/HenkT28/pands-problem-set/blob/master/collatz.py
- http://www.trytoprogram.com/python-programming/python-while-loop/
- https://stackoverflow.com/questions/20372485/what-does-end-exactly-do
I week 5 we looked at data and had to write a program that outputs whether or not today is a weekday. An example of running this program on a Thursday is given below.
- $ python weekday.py
- Yes, unfortunately today is a weekday.
An example of running it on a Saturday is as follows.
- $ python weekday.py
- It is the weekend, yay!
- https://www.codespeedy.com/how-to-find-day-name-from-date-in-python/
- https://stackoverflow.com/questions/9847213/how-do-i-get-the-day-of-week-given-a-date
- https://stackoverflow.com/questions/38063300/php-if-elseif-else-for-day-and-time
This week I had to write program that takes a positive floating-point number as input and outputs an approximation of its square root. You should create a function called sqrt that does this.
- $ python squareroot.py
- Please enter a positive number: 14.5
- The square root of 14.5 is approx. 3.8.
- https://en.wikipedia.org/wiki/Newton%27s_method
- https://www.cs.swarthmore.edu/~grace/cs21/f14/notes/SampleProblems.html
- https://github.com/codevscolor/codevscolor/blob/master/python/find_squareroot.py
- https://stackoverflow.com/questions/8347435/sqrt-takes-exactly-2-arguments-1-given
- https://medium.com/@surajregmi/how-to-calculate-the-square-root-of-a-number-newton-raphson-method-f8007714f64
- https://www.youtube.com/watch?v=tUFzOLDuvaE
For this weeks task I had to write program that reads in a text file and outputs the number of e's it contains. The program should take the filename from an argument on the command line.
- $ python es.py moby-dick.txt
- 116960
- https://stackoverflow.com/questions/22694244/counting-specific-letters-or-symbols-in-a-text-file-in-python
- https://www.gutenberg.org/files/2701/old/moby10b.txt
In week 8 we had to write a program that displays a plot of the functions f(x)=x, g(x)=x2 and h(x)=x3 in the range [0, 4] on the one set of axes.