Tags:
tag this topic
create new tag
view all tags
---+ Exercises for session1: Introduction to !IoT and Python ---++ Exercise 1: * <p>Write a program that calculates and prints the Fibonacci numbers up to 20 iterations. <br /> The Fibonacci numbers are calculated as follows:<br /> F[0] = 0<br /> F[1] = 1<br /> F[n] = F[n-1] + F[n-2]</p> * <p>Modify your program to get the number of iterations from a command line parameter:</p> <p> _fibonacci.py 20_ will calculate and print the same numbers as the exercise above</p> ---++ Exercise 2: Write a program that checks if a number is a prime number. It will either print that it found a prime number or give a valid divisor. Get the number to be tested again from the command line argument as in exercise 1 ---++ Exercise 3: Modify the above programs into functions that can be called from a main program and write this main program into the same file (Test if __name__ is “__main__” to be able to run the program). Then write a main program in a separate file and import the <i>module </i>into your main program. Call the function in the module Do the same thing for the prime example ---++ Exercise 4: Add a module with a function calculating the factorial of a number: factorial(n) = 1*2*3*4… *n ---++ Exercise 5: Finally put the fibonacci, the factorial and the prime module into a packet. How do you have to import and call the functions now? If the number if iterations is smaller than 1, raise a !ValueError ---++ Exercise 6: Convert the packet with the 3 math functions into a class with the methods: * <p>prime</p> * <p>fibonacci</p> * <p>factorial</p> How do you call the functions now? ---++ Exercise 7: Write a callback function printing “Hello” and a program with an endless main loop which calls the callback function once every 2 s. -- %USERSIG{UliRaich - 2019-05-27}% ---++ Comments %COMMENT%
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2019-05-27
-
UliRaich
Home
Site map
AFNOG web
Embedded_Systems web
IoT_Course_English web
IoT_Course_French web
Main web
Sandbox web
TWiki web
AFNOG Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
P
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Register User
E
dit
A
ttach
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback