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
3 Answers
+ 2
why not use a function instead of a variable?
def ipgen():
return random.randint(0,255)
+ 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)}")
0
Both are plausible answers.Thank you