[英]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.