Question: 4 Your Task there must be a decimal point; there must be exactly one digit to the left of the decimal point and this digit

4 Your Task there must be a decimal point;
there must be exactly one digit to the left of the decimal point and this digit must be non-zero;
so, for example 35.27 e 4 and 0.3527 e 4 are not allowed; this is the usual form for scientific notation
and is called normalized scientific notation.
Note that in other contexts when Python displays floats, it sometimes uses a notation similar to
scientific notation but not necessarily following the above constraints, e.g. Python may write an
extra 0 in the exponent, for example, 2.245e-07 instead of 2.245e-7, and when the exponent is non-
positive, Python may put a + symbol, for example, 2.245e+7 instead of 2.245 e 7. For reasons of con-
sistent grading, we require that you do not include an extra 0 or a + symbol in the output of your
to_scientific_notation_no_loop function.
to_scientific_notation_with_loop
This function does the same as the previous one, except that now you are allowed to use loops, but
you are not allowed to use string methods. You are still allowed to use string concatenation with +,
slicing, and the len function.
count_sig_digits
Given an input string argument representing a number that is written in scientific notation, return an
integer that is the number of significant digits. round_significand
This function takes a string of the significand as input argument and a desired number of significant
digits which may be less than, equal to, or greater than the number of digits in the given string. This
function then rounds the significand to the desired number of significant digits, and returns a string
with the rounded significand. This rounding may lead to two digits occurring to the left of the decimal
point, for example, round_significand("9.999",3) returns '10.0'. The starter code provides a similar
example. So for this function, the input significand should be in the desired format with one digit to
the left of the decimal point, but the output might not be. Notes:
f-strings may not be used in this assignment, even though we covered them in lecture 9.
We'll make a few assumptions to keep the assignment manageable and/or to facilitate grading:
We consider only strictly positive numbers.
Page 4
We write large integers without commas. This avoids possible confusion with how numbers are
represented in French where commas and periods are used differently than in English.
A subtle issue arises when you multiply several floats using the multiply function. Python will carry
out the multiplication sequentially (term by term). For each multiplication, the two operands and the
result will be limited to 16 significant digits, since floats are limited to 16 significant digits (or 52 bits
of significand). As a result, the rule of thumb for multiplying several numbers can only be applied
correctly if there is a small number of terms in the product and each of these terms itself has a limited
number of significant digits such that the raw product has no more than 16 significant digits. For this
reason, we will test this function only using examples for which the raw product of all terms has no
more than 16 significant digits.
We provide you with starter code which includes the docstring for each of the functions below. Each docstring
has many examples and these examples constrain the behavior we are expecting for the functions. Please
let us know if you have questions about the behavior for other examples that you may come up with.
Your task is to implement the following functions:
to_scientific_notation_no_loop
Given an input string argument representing a number, this function returns a string representing that
number, written in scientific notation.
For this function, you are not allowed to use loops. Instead, you may use only string methods that we
covered in the lecture, along with concatenation + and slicing. There is another version of this function
below that you need to implement which does not allow you to use string methods and instead allows
you to use loops.
The number represented by returned string must obey the following:
the number of digits in the significand must be equal to the number of significant digits in the
input string, as described earlier in the document;
4 Your Task there must be a decimal point; there

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!