Download this Python script. This Python script is full of syntax, runtime, and semantic errors. Please identify and correct these errors, such that code becomes fully executable and outputs the following message on the screen when running from the Git Bash command line:
The life expectancy for the millennials is projected to be 120 years! (But don't believe it...)
A recent study published in the journal of Nature, discovered that over the past century,
although life expectancy has significantly increased due to technological advances,
the maximum life span of the oldest people in the world has not changed much.
Cardano was the first to introduce complex numbers of the form a + sqrt(-b) into algebra, but he had misgivings about it.
In his solution to an algebra equation, he encountered the solution 5 + sqrt(-15) for the unknown, which is now mathematically represented by
(5+3.872983346207417j)
in Python, which can also be obtained as the addition of real and imaginary numbers in Python like this
5 + sqrt(-15) = (5+3.872983346207417j),
which can also be manually stated as
(5+3.872983346207417j)
One final note:
In python the sqrt function from math and cmath modules are different.
The sqrt function that returns "float" results is sqrt from the math module.
Therefore, if using the math module, then,
sqrt(25) = 5.0000,
which is a float (real number).
Also note that by convention, 0**0 = 1 in Python.
And division by 0, will give you a runtime exception: 1/0 = NaN
Identify at least one example in the code for each of the error types.
Here are a few hints:
- You need to get familiar with string formatting in
print
function. Read the Python tutorials, for example, for more information.
- Note that in Python, the interpreter is sensitive to indentations in your codes. All lines must be aligned at the beginning (except for looping and branching, … which we will get to them later on).
- Become familiar with escape characters in Python, such as
'\n'
,'\t'
, and'\t'
.