Difference: REPLAndStandardPythonProgramming (8 vs. 9)

Revision 92020-05-28 - UliRaich

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

Course on Internet of Things

Exercises Session 1:

Line: 26 to 26
 
  • a/b

If you use integer format when printing the result, you will see the result truncated to an integer. Can you correct changing the format?
Added:
>
>
https://afnog.iotworkshop.africa/pub/IoT_Course_English/REPLAndStandardPythonProgramming/calculatorV1.py.txt
 Improve this program asking the user to enter 2 real numbers (floats) separated by a space. This is how it should look like:

calcOk.png

Line: 36 to 38
  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?
Added:
>
>
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?

Try your parser on this input:

Line: 49 to 53
 
5.3+. not ok
5.3+ not ok
Try also several spaces in between operands and operator.
Added:
>
>
https://afnog.iotworkshop.africa/pub/IoT_Course_English/REPLAndStandardPythonProgramming/calculatorV3.py.txt
 

Exercise 3: Conditions

Like in exercise2, start with 2 numbers a,b with values 5 and 7. In your program check which of the 2 numbers is bigger and print the result.

Line: 116 to 122
 
META FILEATTACHMENT attachment="wallis.png" attr="" comment="" date="1588689113" name="wallis.png" path="wallis.png" size="6212" user="UliRaich" version="1"
META FILEATTACHMENT attachment="wallis1.png" attr="" comment="" date="1588689317" name="wallis1.png" path="wallis1.png" size="15114" user="UliRaich" version="1"
META FILEATTACHMENT attachment="invalidFloat.png" attr="" comment="" date="1588945107" name="invalidFloat.png" path="invalidFloat.png" size="32744" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="calculatorV1.py.txt" attr="" comment="" date="1590658465" name="calculatorV1.py.txt" path="calculatorV1.py.txt" size="438" user="UliRaich" version="1"
META FILEATTACHMENT attachment="calculatorV2.py.txt" attr="" comment="" date="1590658465" name="calculatorV2.py.txt" path="calculatorV2.py.txt" size="1363" user="UliRaich" version="1"
META FILEATTACHMENT attachment="calculatorV3.py.txt" attr="" comment="" date="1590658465" name="calculatorV3.py.txt" path="calculatorV3.py.txt" size="3255" user="UliRaich" version="1"
 
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