Course on Internet of Things
print Hello World!
read in a text using input() and print it
Calculate

Calculate sin(30°)
If you see errors, how do you correct them? Are the results correct?
a+b
a-b
a*b
a/b
If this happens:
when the user mistypes and enters something that is not a real number, can you capture the error and simply ask the user to repeat his input, until you get 2 correct floating point numbers?
https://afnog.iotworkshop.africa/pub/IoT_Course_English/REPLAndStandardPythonProgramming/calculatorV2.py.txt
Bonus points: Writing a parser for user input is rather easy if the numbers and operator are separated by spaces (have a look at the split method of strings). It is quite a bit more tricky if you allow entering calculations without spaces between the operands and the operator. Can you write a parser accomplishing this?
Hint: A very elegant solution to this is the use of regular expressions and Python provides a module helping you with this:
https://docs.micropython.org/en/latest/library/ure.htmlzero or more spaces
followed be zero of more spaces
| Input | ok or not ok |
|---|---|
| 5.3+4.7 | ok |
| 5.3++4.7 | not ok |
| 5..3 + 4.7 | not ok |
| .3+.7 | ok |
| 5.3+4b7 | not ok |
| empty string | not ok |
| 5.3+. | not ok |
| 5.3+ | not ok |
| -1--1 | ok |
| --1--1 | not ok |
Add these series to your class and try. Write a test script exercising the different methods.
Please also have a look at the Wikipedia page on number series: https://en.wikipedia.org/wiki/Series_(mathematics)| I | Attachment | History | Action | Size | Date | Who | Comment |
|---|---|---|---|---|---|---|---|
| |
calcOk.png | r1 | manage | 21.7 K | 2020-05-03 - 19:52 | UliRaich | |
| |
calculatorV1.py.txt | r1 | manage | 0.4 K | 2020-05-28 - 09:34 | UliRaich | |
| |
calculatorV2.py.txt | r1 | manage | 1.3 K | 2020-05-28 - 09:34 | UliRaich | |
| |
calculatorV3.py.txt | r1 | manage | 3.2 K | 2020-05-28 - 09:34 | UliRaich | |
| |
conditions.png | r1 | manage | 28.8 K | 2020-05-03 - 20:25 | UliRaich | |
| |
conversionError.png | r1 | manage | 19.3 K | 2020-05-03 - 19:42 | UliRaich | |
| |
e.png | r2 r1 | manage | 1.5 K | 2022-02-08 - 16:45 | UliRaich | |
| |
euler.png | r1 | manage | 1.5 K | 2022-02-08 - 16:50 | UliRaich | |
| |
exercise_1.odt | r2 r1 | manage | 126.6 K | 2022-02-08 - 17:45 | UliRaich | |
| |
factorial.png | r1 | manage | 2.8 K | 2020-05-04 - 12:48 | UliRaich | |
| |
geometric.png | r1 | manage | 3.9 K | 2020-05-04 - 12:48 | UliRaich | |
| |
harmonic.png | r1 | manage | 1.6 K | 2020-05-04 - 12:53 | UliRaich | |
| |
invalidFloat.png | r1 | manage | 32.0 K | 2020-05-08 - 13:38 | UliRaich | |
| |
ln2.png | r1 | manage | 2.0 K | 2020-05-04 - 12:48 | UliRaich | |
| |
mathSeries.png | r3 r2 r1 | manage | 9.7 K | 2022-02-08 - 17:36 | UliRaich | |
| |
pi.png | r1 | manage | 2.7 K | 2020-05-04 - 12:48 | UliRaich | |
| |
wallis.png | r1 | manage | 6.1 K | 2020-05-05 - 14:31 | UliRaich | |
| |
wallis1.png | r1 | manage | 14.8 K | 2020-05-05 - 14:35 | UliRaich | |
| |
wallis_prod.png | r4 r3 r2 r1 | manage | 4.2 K | 2022-01-27 - 09:46 | UliRaich |