|
META TOPICPARENT |
name="ASP2022" |
Exercises |
|
Write a program that prints "Hello World!" 7 times. Do this using a while loop and in a second program, using a for loop, Which of the programs is more elegant?
This is the end of the first exercise session |
|
> > |
|
| Second exercise session |
|
> > | MicroPython modules
Modify the loop program in such a way that "Hello World!" is printed only every second. Import the utime module and make the program sleep for 1s after each print statement.
Import the sin function and the value of pi from the math module
from math import sin,pi
Remember that the sin function takes its values in units of radians. The angle values for a complete sin period will range 0 .. 2*pi. Print the angles and the sin values for a full sin period using 30 equidistant angle values. (x and sin(x)).
Creating and using your own function
Create a sin_deg function which takes angles in units of degrees instead of radians. Print the angles and the sin values for 36 equidistant angle values.
You may copy/paste the result to a new editor window in thonny and save them to a file on the PC. Then you can plot the function using gnuplot.
End of the second exercise session
|
|
-- Uli Raich - 2022-10-14 |
|
META FILEATTACHMENT |
attachment="helloWorld.png" attr="" comment="" date="1665842121" name="helloWorld.png" path="helloWorld.png" size="73165" user="UliRaich" version="1" |
|
|
> > |
META FILEATTACHMENT |
attachment="gnuplot_sin.png" attr="" comment="" date="1665866878" name="gnuplot_sin.png" path="gnuplot_sin.png" size="30601" user="UliRaich" version="1" |
|