Aug-18-2022, 03:38 PM
(This post was last modified: Aug-18-2022, 04:19 PM by rob101.
Edit Reason: typo
)
You've made a good start.
For functions, get in to the practice of using doc strings, like this:
Personally, I wound not have the main body of the code as a function, rather have it as a body of code in its own right, with all the functions above the main body.
The next thing to do is to sanitize the user input. As an example, if a user does not enter a number, have your script catch that and once again ask for a number. This can be done without using
I'll not present you with a large list of things to do right now, but there are other improvements that can be made, such as taking all of the input in one hit, then extracting the elements so that the calculation can be made.
Hint: run this...
For functions, get in to the practice of using doc strings, like this:
def add(n1, n2): """ Takes two floating point numbers and returns the sum """That way the text can be extracted with:
print(add.__doc__)...
add
, in the above example being the function name.Personally, I wound not have the main body of the code as a function, rather have it as a body of code in its own right, with all the functions above the main body.
The next thing to do is to sanitize the user input. As an example, if a user does not enter a number, have your script catch that and once again ask for a number. This can be done without using
try
/ except
. If you want me (or anyone else) to show you how that can be done, then fair enough; just ask, but you'll learn a good deal more if you can work that out for your self. Hint: write a function to check the user input before the rest of your script accepts it.I'll not present you with a large list of things to do right now, but there are other improvements that can be made, such as taking all of the input in one hit, then extracting the elements so that the calculation can be made.
Hint: run this...
calculate = list(input(": ")) print(calculate)... and enter
7*4
Sig:
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein