这里使用了三个知识点:

1、函数的定义

2、用户自定义输入input

3、try-except模块捕获了错误,如果失败向用户显示了一个自定义的错误消息

def get_remote_sysinfo():
    print("Example:www.baidu.com")
    remote_host = input("Please input remot_host:")
    try:
        print("IP address: %s" %socket.gethostbyname(remote_host))
    except socket.error:
        print ("Sorry!~ Don't Found %s" %remote_host)
get_remote_sysinfo()


执行正确结果:

wKioL1mSXGyiOVA2AAA36oLFvv8467.jpg-wh_50


错误结果:

wKioL1mSXJPRcbchAAA1bGUMhps465.jpg-wh_50


注意事项:

函数定义:函数内代码要缩进,不然会语法报错,切记!~