Difference: REPLAndStandardPythonProgramming (2 vs. 3)

Revision 32020-05-04 - UliRaich

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

Course on Internet of Things

Exercises Session 1:

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

Added:
>
>
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 + 4 ok
 
Deleted:
<
<
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
 

Exercise 3:

Changed:
<
<
Like in exercise2, start with 2 number a,b with values 5 and 3. In your program check which of the 2 numbers is bigger and print the result. Then ask the user for 2 integer numbers. Make sure he enters 2 correct numbers and capture possible errors. This is a typical output:
>
>
Like in exercise2, start with 2 numbers a,b with values 5 and 3. In your program check which of the 2 numbers is bigger and print the result.

Then improve the program asking the user for 2 integer numbers. Make sure he enters 2 correct numbers and capture possible errors. This is a typical output:

  conditions.png
 
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