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
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 nonzero;
so for example e and e 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, eg Python may write an
extra in the exponent, for example, instead of and when the exponent is non
positive, Python may put a symbol, for example, instead of e For reasons of con
sistent grading, we require that you do not include an extra or a symbol in the output of your
toscientificnotationnoloop function.
toscientificnotationwithloop
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.
countsigdigits
Given an input string argument representing a number that is written in scientific notation, return an
integer that is the number of significant digits. roundsignificand
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, roundsignificand returns 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:
fstrings may not be used in this assignment, even though we covered them in lecture
We'll make a few assumptions to keep the assignment manageable andor to facilitate grading:
We consider only strictly positive numbers.
Page
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 significant digits, since floats are limited to significant digits or 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 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 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:
toscientificnotationnoloop
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;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
