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.

5/9/2017 9:22:00 PM

Kutay Güler

9 Answers

New Answer


create a list r=[x,y,z] import random print(random.choice(r)) but it's easy to find with a Google recherche...


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))


Yeah, except defining x,y,z just writing directly is more practical


thanks dude, you are right I shouldn't be that lazy to look up. I'll terminate this post later


no need to terminate it. It was the type of questions this forum is here for.


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 ?


I've modified the code...


I'd like to ask other questions related to greeting messages but I haven't finished my course yet, thanks for the comments!


the code without problems https://code.sololearn.com/c8gq4d1C2SlE/?ref=app