I want my script to repeat input
question until the user prompt the right answer. After the user prompted the right answer, the script has to go on with the relative if statement In this case hostname
or file
. I came out with the below code, however seems to fall into infinite loop.
import socket
def ipFromHost():
opt1 = input('Do you want provide hostname or file: ')
while opt1 != 'hostname' or 'file':
input('Please, type "hostname" or "file"')
if opt1 == 'hostname':
optHostname = input('Please, provide hostname: ')
print(socket.gethostbyname(optHostname.strip()))
elif opt1 == 'file':
optFile = input('Please, provide file name: ')
with open(optFile) as inputFile:
for i in inputFile:
print(socket.gethostbyname(i.strip()))
Thanks!