Lab - Mapping of Net
Lab - Mapping of Net
Objectives
Part 1: Launch VirtualBox and Enter the I2IoT server VM
Part 2: Python Basics
Part 3: IDLE for Python
Background
Python, a programming language, allows for simpler statements. Python is very easy to use, powerful, and
versatile. It has become the language of choice for many IoT developers. One of the main reasons for the
popularity of Python is the developer community. Python developers have created and made available many
specific modules that can be imported into any program to immediately lend added functionality.
Scenario
In this lab, you will learn and practice some basic Python programming. More specifically, we will use Python
version 3 in the lab.
Required Resources
A modern personal computer with internet access and sufficient RAM.
VirtualBox with I2IoT server installed.
© 2018 Cisco and/or its affiliates. All rights reserved. This document is Cisco Public. Page 1 of 7
Lab – Basic Python Programming
b. Click I2IoT – GUI on the left pane to launch the server VM.
c. The default username is IoT_user with no password. Click the blue bar IoT_user in the middle of the
screen to login to the VM.
© 2018 Cisco and/or its affiliates. All rights reserved. This document is Cisco Public. Page 2 of 7
Lab – Basic Python Programming
c. Use the ls command to show the list of contents in the current directory. Use the ls command with the -l
option to show detailed information about the contents.
d. Use the cd Documents command to change the directory to the /home/IoT_user/Documents directory.
Verify by using the command pwd.
e. To check the version of Python installed on the VM, issue the python3 --version command.
© 2018 Cisco and/or its affiliates. All rights reserved. This document is Cisco Public. Page 3 of 7
Lab – Basic Python Programming
b. Perform calculations.
>>> 1 + 2
3
>>> 2 * 4
8
>>> 6 / 2
3.0
>>>
c. Print a text string.
>>> “How are you?”
‘How are you?’
>>>
d. Use the type() command to determine the basic data type: int, float, string, Boolean.
>>> type(65)
<class 'int'>
>>> type(45.6)
<class 'float'>
>>> type("Hi!")
<class 'str'>
>>> type(True)
<class 'bool'>
>>> 1<2
True
© 2018 Cisco and/or its affiliates. All rights reserved. This document is Cisco Public. Page 4 of 7
Lab – Basic Python Programming
>>> 1<1
False
>>> 1==1
True
>>> 1>=1
True
>>>
e. Create a variable.
>>> x=3
>>> x*5
15
>>> "Good!"*x
'Good!Good!Good!'
>>>
f. Combine multiple strings together and print as one string.
>>> str1="Cisco"
>>> str2="Networking"
>>> str3="Academy"
>>> space=" "
>>> print(str1+space+str2+space+str3)
Cisco Networking Academy
>>>
g. Convert data type from a numeric number to a string.
>>> x=5
>>> str(x)
>>> ‘5’
>>> y=4.2
>>> str(y)
>>> y=‘4.2’
>>>
h. Note that integers are not rounded up when converting from float. The decimal is ignored.
>>> int(8.21)
8
>>> int(8.99)
8
>>> int(8.21) + int(8.99)
16
>>>
i. Convert an integer to a float.
>>> x=5
>>> x
5
>>> float(x)
5.0
>>> type(x)
<class 'int'>
>>> x=float(x)
>>> type(x)
<class 'float'>
© 2018 Cisco and/or its affiliates. All rights reserved. This document is Cisco Public. Page 5 of 7
Lab – Basic Python Programming
>>> x
5.0
>>>
j. Obtain user input.
>>> name=input("What is your name? ")
What is your name? John
>>> print("Hi " + name + ", it is nice to meet you!")
Hi John, it is nice to meet you!
>>>
k. Use quit() to exit interactive interpreter.
b. Click File -> New File to open a new (untitled) Python script.
© 2018 Cisco and/or its affiliates. All rights reserved. This document is Cisco Public. Page 6 of 7
Lab – Basic Python Programming
c. Type the code in the script print(“Hello World!”), note the codes are colored, and open and close
parentheses are matched.
d. Click File -> Save, save the current script as 1.py in the current directory. Click Save button.
e. Click Run -> Run Module (or press F5). The shell window will display the result.
© 2018 Cisco and/or its affiliates. All rights reserved. This document is Cisco Public. Page 7 of 7