python heelp | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

python heelp

import random def rand50(): rand=[random.randrange(0, 255) for i in range(4)] return rand print((rand50()) but i need using def and return random ip adress and then print 20 ip adress . IP must be like this: 192.168.0.1

4th Nov 2018, 11:34 PM
Kasia Herasymenko
Kasia Herasymenko - avatar
6 Answers
+ 1
from random import randint network = "10.20.30." for ii in range(20): ip = network + str(randint(0, 255)) print(ip) # Obviously you can add elaboration # like dupe-checking, etc. # This is just for a general idea.
5th Nov 2018, 12:43 AM
non
+ 1
# More or less @ 02h00... from random import randint def newIP(netw): ip = netw + str(randint(0,255)) return ip for ii in range(20): print(newIP("192.168.0.")) # The rest can be figured out with # minor effort + research.
5th Nov 2018, 11:16 PM
non
+ 1
Thank you so much
5th Nov 2018, 11:18 PM
Kasia Herasymenko
Kasia Herasymenko - avatar
0
The question is unclear. May I assume you want 20 random IP addresses and you want them on the same network? K1.K2.K3.N basically?
5th Nov 2018, 12:06 AM
non
0
Yes
5th Nov 2018, 12:07 AM
Kasia Herasymenko
Kasia Herasymenko - avatar
0
sorry, but i not exactly understand how to write this by making function(def)
5th Nov 2018, 1:01 AM
Kasia Herasymenko
Kasia Herasymenko - avatar