Issue
Need help,
I expected the output like this
1.1.1.1 is server0
1.1.1.2 is server1
1.1.1.3 is server2
1.1.1.4 is server3
But I don't get the output like I expected. Here's my code
IP = ['1.1.1.1', '1.1.1.2', '1.1.1.3', '1.1.1.4']
for ip in IP:
for i in range(len(IP)):
print(ip + ' is ' + 'server'+ str(i))
Output:
1.1.1.1 is server0
1.1.1.1 is server1
1.1.1.1 is server2
1.1.1.1 is server3
1.1.1.2 is server0
1.1.1.2 is server1
1.1.1.2 is server2
1.1.1.2 is server3
1.1.1.3 is server0
1.1.1.3 is server1
1.1.1.3 is server2
1.1.1.3 is server3
1.1.1.4 is server0
1.1.1.4 is server1
1.1.1.4 is server2
1.1.1.4 is server3
Can someone help me?
Solution
You don't need two loops here. Simply write:
for i in range(len(IP)):
print(IP[i] + ' is ' + 'server'+ str(i))
Output:
1.1.1.1 is server0
1.1.1.2 is server1
1.1.1.3 is server2
1.1.1.4 is server3
Answered By - Taohidul Islam
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.