Difference between revisions of "IoT Coding basics"
Line 6: | Line 6: | ||
=== Hello World! === | === Hello World! === | ||
− | In this section, we will run Bash and Python hello world examples. | + | In this section, we will run Bash and Python hello world examples. |
+ | |||
+ | Bash | ||
#!/bin/bash | #!/bin/bash | ||
Line 12: | Line 14: | ||
echo "Hello Bash World!" | echo "Hello Bash World!" | ||
+ | Python | ||
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||
# This is a python comment | # This is a python comment | ||
print("Hello Python World!") | print("Hello Python World!") | ||
+ | |||
+ | Use your favourite text editor to create these two files hello_world.sh and hello_world.py. Make sure you provide them with execute permissions | ||
+ | |||
+ | chmod 777 hello_world.sh | ||
+ | |||
+ | And | ||
+ | |||
+ | chmod 777 hello_world.py | ||
+ | |||
+ | You can execute them with | ||
+ | |||
+ | ./hello_world.sh | ||
+ | |||
+ | And | ||
+ | |||
+ | ./hello_world.py | ||
+ | |||
+ | The contents of the code should be prety straightforward. The only link that may need explaining is the shebang first line. The shebang line allows the script to executed like a standalone executable without typing python, ruby, et cetera. It also immediately tells someone looking at the code, what language has been used and in the case of python it can specify the version of python that is used to execute it. | ||
=== Modify the Code 1 === | === Modify the Code 1 === |
Revision as of 01:14, 9 June 2020
Lab showing bash and python as well as execution times Provide some fix the code as well as complete the code examples. Dealing with numbers, printing them, division and decimals
Contents
Introducing Bash and Python
Hello World!
In this section, we will run Bash and Python hello world examples.
Bash
#!/bin/bash # This is a bash comment echo "Hello Bash World!"
Python
#!/usr/bin/env python3 # This is a python comment print("Hello Python World!")
Use your favourite text editor to create these two files hello_world.sh and hello_world.py. Make sure you provide them with execute permissions
chmod 777 hello_world.sh
And
chmod 777 hello_world.py
You can execute them with
./hello_world.sh
And
./hello_world.py
The contents of the code should be prety straightforward. The only link that may need explaining is the shebang first line. The shebang line allows the script to executed like a standalone executable without typing python, ruby, et cetera. It also immediately tells someone looking at the code, what language has been used and in the case of python it can specify the version of python that is used to execute it.
Modify the Code 1
Examine the following two code snippets written in Bash and Python.
#!/usr/bin/env python3 for x in range(5): print(x)
Upgrade the Python2 code
Create an upgrade this code to python3
Averaging a value
Exponentially Weighted Moving Averages =
Glueing code together =
Glueing code together
- running Python from bash
- running bash from python
Code resiliency
Reving processes
Virtual Terminals
Complete some common Fibonacci or squares examples