简体   繁体   English

我不知道为什么我的 delete 和 ping 不起作用。 Python

[英]I don't know why my delete and ping wont work. Python

import platform
import subprocess
import webbrowser

ipAddress = []

def show_ip():
    i = -1
    if(len(ipAddress) ==0):
        print('There are no IPs assigned')
        print ("")
    else:
        print("----List of IP Addresses----")
        for z in ipAddress:
            i = i + 1
            print("IP (", i, "):" , z)
        print("")

def add_ip():
    addIP = input('Enter IP: ')
    ipAddress.append(addIP)
    print('IP Added')
    print('')

def update_ip():
    updateIP = int(input('Enter IP [index] to update: '))
    newIP = input('Enter new IP: ')
    ipAddress[updateIP] = newIP
    print('Ip Updated')
    print('')

def delete_ip():
    delIP = input('Enter IP Address to Delete: ')
    ipAddress.remove(delIP)
    print ('IP', delIP, 'Deleted')
    print('')

def ping_ip():
    pingAddress = ""
    for b in ipAddress:
        if(platform.system() == 'Windows'):
            pingAddress = '-n'
        else:
            pingAddress = '-c'

        status = subprocess.call(['ping', pingAddress, '1', '127.0.0.1'])
        if status == 0:
            print (b, "Ping Successful")
        elif status == 2:
            print(b, 'Ping No respnse')
        else:
            print (b, 'Ping Failed')
    print('')

while(True):

        print ('------MENU------')
        print('[1] - Show Stored IPs')
        print('[2] - Add IP Address')
        print('[3] - Update IP Address')
        print('[4] - Delete IP Address')
        print('[5] - Ping IP Address')
        print('[6] - Help') 
        print('[7] - Exit ')

        choice = input('Please enter your choice: ')
        print('')

        if (choice =='1'):
            show_ip()
        elif (choice =='2'):
            add_ip()
        elif (choice =='3'):
            update_ip()
        elif (choice =='4'):
            delete_ip
        elif (choice =='5'):
            ping_ip
        elif (choice =='6') :
            webbrowser.open('help.html')    
        elif (choice =='7'):
            exit()
        else:
            print('Invalid input')

I dont know why option 4 and 5 wont work.我不知道为什么选项 4 和 5 不起作用。 It just loops again and again in the same menu that I did.它只是在我所做的同一个菜单中一次又一次地循环。 Can someone help me with it because im going nuts figuring out why it doesn't work.有人可以帮我解决这个问题,因为我正在疯狂地弄清楚为什么它不起作用。 I would be so thankful if someone figures it out because I tried for over 4 hours re arranging the code to get it to work如果有人弄清楚了,我会非常感激,因为我尝试了 4 多个小时重新安排代码以使其正常工作

你忘记了 delete_ip 和 ping_ip 后面的括号 ()。

You are not calling functions:您不是在调用函数:

elif (choice =='4'):
    delete_ip
elif (choice =='5'):
    ping_ip

try:尝试:

elif (choice =='4'):
    delete_ip()
elif (choice =='5'):
    ping_ip()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的gridsearchCV不起作用,我也不知道为什么 - My gridsearchCV don't work and i don't know why 我的 Python while 循环没有终止,我不知道为什么 - My Python while loop is not terminating and I don't know why 蟒蛇。 欧拉计划Q35。 有解决方案,但我不明白为什么其他方法不起作用。 - Python. Project Euler Q35. Got a solution but I don't understand why other method doesn't work. 我在 python 中创建了一个收据生成器,并将数据从 MySQL 提取到文本区域,但它不起作用。 我不知道我在哪里犯了错误 - I creating a receipt generator in python and I fetch data from MySQL to a text area but it's not work. I don't know that where I making the mistake 我的 if else 输入循环不起作用,我不知道为什么 - My if else loop for an input doesn't work and I don't know why For循环python(初学者):不知道为什么这行不通 - For loops python (beginner): Don't know why this won't work 在 python 上需要帮助。 我不知道为什么它不起作用 - Need help on python. I don't know why it doesn't work Java 程序不像 python 程序那样工作,我不知道为什么 - Java program doesn't work like python program and I don't know why 我不知道为什么这个 for 循环程序不起作用(python)。 解决方案? - I don't know why this for loop program doesn't work (python). Solutions? 我不知道为什么这个 Python 编程代码不起作用 - I don't know why this Python Programming code doesn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM