0

Random Welcome Messages (python)

Let's say there are different variables such as x,y,z x = "bla" y = "blabla" z = "blablabla" I want to see just one of them randomly when I run the code, like welcome messages in Minecraft How can I do it? Thanks in advance.

9th May 2017, 9:22 PM
Kutay Güler
Kutay Güler - avatar
9 Respuestas
+ 5
create a list r=[x,y,z] import random print(random.choice(r)) but it's easy to find with a Google recherche...
9th May 2017, 9:28 PM
Hbeo
Hbeo - avatar
+ 3
instead of x="" y="" z="" ... just make a list of the possible welcome messages.. These top 3 lines will do what you want. #Import random module import random #Make a list of the messages x=["Welcome","Enter if you dare","Go away"] #use random.choice() to print one print(random.choice(x)) #Just for fun #10 random picks from the list for i in range(10): print(random.choice(x))
10th May 2017, 9:48 AM
LordHill
LordHill - avatar
+ 2
Yeah, except defining x,y,z just writing directly is more practical
10th May 2017, 12:49 PM
Kutay Güler
Kutay Güler - avatar
+ 1
thanks dude, you are right I shouldn't be that lazy to look up. I'll terminate this post later
9th May 2017, 9:30 PM
Kutay Güler
Kutay Güler - avatar
+ 1
no need to terminate it. It was the type of questions this forum is here for.
10th May 2017, 12:09 AM
LordHill
LordHill - avatar
+ 1
By the way, I defined x,y,z's like x = "Welcome back" and wrote the rest of the code as hbeo indicated. It printed out 'no output' once. Why might that have happened ?
10th May 2017, 7:12 AM
Kutay Güler
Kutay Güler - avatar
+ 1
I've modified the code...
10th May 2017, 2:30 PM
Hbeo
Hbeo - avatar
0
I'd like to ask other questions related to greeting messages but I haven't finished my course yet, thanks for the comments!
10th May 2017, 7:06 AM
Kutay Güler
Kutay Güler - avatar
10th May 2017, 12:31 PM
Hbeo
Hbeo - avatar