Difference: REPLAndStandardPythonProgramming (3 vs. 4)

Revision 42020-05-04 - UliRaich

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

Course on Internet of Things

Exercises Session 1:

Introductory remarks:

The scripts we are going to develop during these exercises do not depend on any system issues: We do not use command line arguments not available in MicroPython nor do we use any hardware specific features which are not available on a PC. The exercises can therefore be developed and run on the ESP32 but also on any standard PC with Python3 installed.

Changed:
<
<

Exercise 1:

>
>

Exercise 1: Use of REPL

  Connect to your ESP32 with minicom or thonny.
Line: 14 to 14
 
  • 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?

Changed:
<
<

Exercise 2:

>
>
  • Finally make the "print Hello World!" command a script and execute it.

Exercise 2: A simple calculator

  Write a script that assigns the values 5 and 3 to the variables a and b respectively
Line: 46 to 47
 
5.3+4b7 not ok
empty string not ok
5.3+. not ok
Changed:
<
<
5.3 + 4 ok

Exercise 3:

>
>
Try also several spaces in between operands and operator.

Exercise 3: Conditions

  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

Added:
>
>

Exercise 4: The Fibonacci series

The Fibonacci number series is defined as:

F(0) = 0; F(1) = 1

F(n) = F(n-1) + F(n-2)

  • Calculate and print out the Fibonacci numbers up to F(n). Get n from the user where n >= 0
Try your program for n=0, n=1, n=2, n=3, n=20

  • Ask the user up to which is the maximum number up to which you should calculate.
  -- Uli Raich - 2020-05-03
 
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