Skip to content
This repository was archived by the owner on Aug 21, 2018. It is now read-only.

Commit c729fd2

Browse files
committed
module4 lab4 sample code
0 parents  commit c729fd2

8 files changed

Lines changed: 150 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
print ("I'm not a function")
2+
3+
def my_function():
4+
print("Hey I'm a function!")
5+
6+
7+
def brett(val):
8+
for i in range(val):
9+
print("I'm a function with args!")
10+
11+
12+
13+
my_function()
14+
brett(5)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
my_list=[5,'joe']
2+
print (my_list[1])
3+
4+
my_tuple=('brett','Cisco',9)
5+
print (my_tuple[1])
6+
7+
8+
my_dict={"red":1,"green":2}
9+
print(my_dict["green"])
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
print ("Hello World!")
3+
4+
print ("How are you?")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
print ("Helloworld!")
2+
3+
num = 1
4+
5+
if num < 1:
6+
print ("I'm less than 1!")
7+
print ("Goodbye Cruel World!")
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
food={"vegetables":["carrots","kale","cucumber","tomato"]}
2+
3+
4+
cars={"sports":{"Porsche":"Volkswagon","Viper":"Dodge","Corvette":"Chevy"}}
5+
6+
7+
8+
dessert={"iceCream":["Rocky-Road","strawberry","Pistachio-Cashew","Pecan-Praline"]}
9+
10+
11+
soup={"soup":{"tomato":"healthy","onion":"bleh!","vegetable":"goodForYou"}}
12+
13+
14+
ticket={"response": {"serviceTicket": "ST-16891-ugqKRVvCfPJcEaGXnGEN-cas","idleTimeout": 1800,"sessionTimeout": 21600},"version": "1.0"}
15+
16+
17+
network={"Network":{"router":{"ipaddress":"192.168.1.21","mac_address":"08:56:27:6f:2b:9c"}}}
18+
19+
20+
hosts={"response": [{"id": "4c60d6a7-4812-40d6-a337-773af2625e56","hostIp": "65.1.1.86","hostMac": "00:24:d7:43:59:d8","hostType": "wireless"},{"id": "3ef5a7c3-7f74-4e57-a5cb-1448fbda5078","hostIp": "207.1.10.20","hostMac": "5c:f9:dd:52:07:78","hostType": "wired"},{"id": "12f9c920-24fa-4d32-bf39-4c63813aecd8","hostIp": "212.1.10.20","hostMac": "e8:9a:8f:7a:22:99","hostType": "wired"}],"version": "1.0"}
21+
22+
23+
devices={"response": [
24+
{
25+
"family": "Switches and Hubs",
26+
"type": "Cisco Catalyst 2960C-8PC-L Switch",
27+
"serialNumber": "FOC1637Y3FJ",
28+
"role": "CORE",
29+
"reachabilityStatus": "Reachable",
30+
"instanceUuid": "2dc30cac-072e-4d67-9720-cc302d02695a",
31+
"id": "2dc30cac-072e-4d67-9720-cc302d02695a"
32+
},
33+
{
34+
"family": "Unified AP",
35+
"type": "Cisco 3500I Unified Access Point",
36+
"serialNumber": "FGL1548S2YF",
37+
"role": "ACCESS",
38+
"reachabilityStatus": "Reachable",
39+
"instanceUuid": "17184480-2617-42c3-b267-4fade5f794a9",
40+
"id": "17184480-2617-42c3-b267-4fade5f794a9"
41+
}
42+
],
43+
"version": "1.0"
44+
}
45+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
network1={"Network":{"routers":[{"ipaddress":"192.168.1.21","mac_address":"08:56:27:6f:2b:9c"},{"ipaddress":"192.168.32.15","mac_address":"3a:24:37:4f:5b:1d"}],"switches":[{"ipaddress":"192.168.32.1","mac_address":"3a:24:37:4f:5b:1d"}]}}
2+
3+
def read_network(network1):
4+
#get the device type name
5+
for device in network1["Network"]:
6+
print("Device is: " + device)
7+
#get the attributes for each device. Returns a dictionary for each
8+
for attrib in network1["Network"][device]:
9+
print("Device attributes are: " + str(attrib))
10+
#parse the attributes for each device
11+
for val in attrib:
12+
print ("Device attribute values are: " + val + " " + attrib[val])
13+
print() #add extra line for separation
14+
15+
16+
read_network(network1)
17+
18+
19+
#Assignment:
20+
network2={"Network":{"routers":[{"ipaddress":"192.168.1.21","mac_address":"08:56:27:6f:2b:9c"}],"switches":[{"ipaddress":"192.168.32.1","mac_address":"3a:24:37:4f:5b:1d"}],"hosts":[{"ipaddress":"192.168.32.5","mac_address":"3b:25:31:4a:5c:3f"},{"ipaddress":"192.168.32.8","mac_address":"4b:15:32:43:51:3c"}]}}
21+
22+
23+
24+
25+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
print ("Hello World!")
2+
print()
3+
4+
for i in range(5):
5+
print (str(i) + " I'm alive!")
6+
print()
7+
8+
basket=["apple","peach","pear","cherry"]
9+
for fruit in basket:
10+
print (fruit)
11+
print()
12+
13+
my_color={"red":1,"blue":2,"green":3}
14+
for color in my_color:
15+
print (color + " %d" % my_color[color]);
16+
print()
17+
18+
name = "Brett"
19+
if name == "Brett":
20+
print ("Brett who?")
21+
else:
22+
print ("Nice name!")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
donut={"type":"donut","flavors":{"flavor":[{"type":"chocolate","id":"1001"}, {"type":"glazed","id":"1002"},{"type":"sprinkled","id":"1003"}]}}
2+
3+
#Parse JSON without loops
4+
print(donut["flavors"]["flavor"][0]["id"] + " " + donut["flavors"]["flavor"][0]["type"])
5+
print(donut["flavors"]["flavor"][1]["id"] + " " + donut["flavors"]["flavor"][1]["type"])
6+
print(donut["flavors"]["flavor"][2]["id"] + " " + donut["flavors"]["flavor"][2]["type"])
7+
print()
8+
9+
#Parse JSON with loops
10+
for hungry in donut["flavors"]["flavor"]:
11+
print(hungry["id"] + " " + hungry["type"])
12+
print()
13+
14+
15+
cars={"sports":{"porsche":"Volkswagon","Viper":"Dodge","Corvette":"Chevy"}}
16+
#Parse JSON without loops
17+
print("porsche " + cars["sports"]["porsche"])
18+
print("Viper " + cars["sports"]["Viper"])
19+
print("Corvette " + cars["sports"]["Corvette"])
20+
print()
21+
22+
#Parse JSON with loops
23+
for auto in cars["sports"]:
24+
print(auto + " " + cars["sports"][auto])

0 commit comments

Comments
 (0)