Course on Internet of Things

Exercises Session 1:

Exercise 1:

Connect to your ESP32 with minicom or thonny.

Using REPL:

  • print “Hello World!”

  • read in a text using input() and print it

  • Calculate

    calculations.png

  • Calculate sin(30°)
    If you see errors, how do you correct them? Are the results correct?

Exercise 2:

Write a script that assigns the values 5 and 3 to the variables a and b respectively

Print the results of 4 basic arithmetic operations:

  • a+b

  • a-b

  • a*b

  • a/b

Which result do you observe for division? Can you correct?

Improve this program asking the user to enter 2 integers separated by a space. If this happens when the user mistypes and enters something that is not an integer can you capture the error and simply ask him to repeat his input until you get 2 correct integer numbers?

Bonus points: Writing a parser is quite easy if the numbers are separated. It is quite a bit more tricky if you allow entering calculations with spaces between the operands and the operator. Can you write a parser accomplishing this?

Exercise 1:

Connect to your ESP32 with minicom or thonny.

Using REPL:

  • 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?

Exercise 2:

Write a script that assigns the values 5 and 3 to the variables a and b respectively

Print the results of 4 basic arithmetic operations:

  • a+b

  • a-b

  • a*b

  • a/b

Which result do you observe for division? Can you correct?

Improve this program asking the user to enter 2 integers separated by a space. What happens when the user mistypes and enters something that is not an integer?

Can you capture the error and simply ask him to repeat his input until you get 2 correct integer numbers?

Exercise 3:

Ask the user for 2 integer numbers. Check with one is bigger and print the result:

Running the program should result in output as shown below:

Exercise 3:

Ask the user for 2 integer numbers. Check with one is bigger and print the result:

Running the program should result in output as shown below:

-- Uli Raich - 2020-05-03

Comments

Edit | Attach | Watch | Print version | History: r17 | r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r1 - 2020-05-03 - UliRaich
 
  • Edit
  • Attach
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