Fundamentals of Network Automation Using Python (def not working)

This course: Fundamentals of Network Automation Using Python, offers scripts that work on my ubuntu/python 3.10.4 until we get to use the def() function. The scripts after these lessons do not output errors, or print (), or anything at all. I think the scripts need to be revised/updated/re-tested. Please help. I can run the scripts, but they return nothing. Not even an error.

Hello!

Can you provide more information on the specific tasks or video or lab?

Conditionals & Functions - Lab Task
the script does not return any output, no error nothing. I am running ubuntu 3.10.4
If I remove def(), then I can print and do things. Basically def does not work on that script. Or any other script after the lesson. I am stocked on that lesson.

Did you try this?

def device_ip(temp):
dict1 = {“hostname”: “R1”, “OS”: “IOS-XE”, “mgmt-ip”: “10.1.1.1”}
dict2 = {“hostname”: “R2”, “OS”: “IOS-XR”, “mgmt-ip”: “10.1.1.2”}
if temp in dict1[“OS”] == “IOS-XE”:
print(“The management IP of”, dict1[“hostname”], “is”, dict1[“mgmt-ip”])
elif temp in dict2[“OS”] == “IOS-XR”:
print(“The management IP of”, dict2[“hostname”], “is”, dict2[“mgmt-ip”])
else:
print(“This device has an unknown image”)

Make sure indentation is correct

1 Like

Hello Rohit, thanks for getting back to me. Yes I am using Atom editor and ubuntu linux to run python scripts as you type them on the lessons. Everything was working fine until we got to def() that returns no output at all. Not even an error:

atom device_ip.py

def device_ip(temp):
dict1 = {“hostname” : “R1”, “OS”: “IOS-XE”, “mgmt-ip”: “10.1.1.1”}
dict2 = {“hostname” : “R1”, “OS”: “IOS-XR”, “mgmt-ip”: “10.1.1.@”}
if temp in dict1[“OS”] == “IOS-XE”:
print(“The management IP of”, dict1[“hostname”], “is”, dict1[“mgmt-ip”])
elif temp in dict2[“OS”] == “IOS-XR”:
print(“The management IP of”, dict2[“hostname”], “is”, dict2[“mgmt-ip”])
else:
print(“This device has an unknown image”)

1 Like