0

python multiple random values for the same string?

FOR EXAMPLE: import random ip_generator =random.randint(0,255) ip_generator =random.randint(0,255) ip_generator =random.randint(0,255) ip_generator =random.randint(0,255) print(f"{ip_generator}.{ip_generator}.{ip_generator}.{ip_generator}") How can you give a random value using only one variable

1st Aug 2018, 5:38 PM
BananasDZN sd
BananasDZN sd - avatar
3 Respuestas
+ 2
why not use a function instead of a variable? def ipgen(): return random.randint(0,255)
1st Aug 2018, 6:10 PM
JME
+ 3
# Without any variable at all, and without defining a function: import random print(f"{random.randint(0,255)}.{random.randint(0,255)}.{random.randint(0,255)}.{random.randint(0,255)}")
1st Aug 2018, 6:14 PM
visph
visph - avatar
0
Both are plausible answers.Thank you
1st Aug 2018, 6:22 PM
BananasDZN sd
BananasDZN sd - avatar