Difference: REPLAndStandardPythonProgramming (9 vs. 10)

Revision 102020-06-01 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Exercises"

Course on Internet of Things

Exercises Session 1:

Line: 42 to 42
  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?
Added:
>
>
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.html

 Try your parser on this input:
Input ok or not ok
5.3+4.7 ok
Line: 52 to 56
 
empty string not ok
5.3+. not ok
5.3+ not ok
Added:
>
>
-1--1 ok
--1--1 not ok
 Try also several spaces in between operands and operator.

https://afnog.iotworkshop.africa/pub/IoT_Course_English/REPLAndStandardPythonProgramming/calculatorV3.py.txt

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback