Ask coding questions

← Back to all posts
halp me pls
LilWolfy

hullo! g’day!

um so I’m creating a game and i don’t know how to create a variable where it’s random

i think it’s like this:
ex:
import random

x = random.randint(1,10)

but you see the “(1,10)”?
can you make it into words? pls show me

thank u uwu

Answered by SixBeeps [earned 5 cycles]
View Answer
Voters
LilWolfy
Comments
hotnewtop
SixBeeps

Hmm, what do you mean by "make it into words"? Like, do you want it to pick a random word, or are you looking for someone to explain what it means?

LilWolfy

@SixBeeps Yes, I meant pick a random word

ex:

let’s say i want it to choose from: hi, bye, hello, or good morning.

how do you add the code for that?

(assuming it’s something like this:
import random

x = random.randint(blah blah blah)
print(x)

SixBeeps

@LilWolfy Real quick, are you familiar with lists?

LilWolfy

@SixBeeps Yep, I am. Why?

LilWolfy

@SixBeeps I’m pretty it’s like: ‘lbahbe’,’asdukwef’,… right?

SixBeeps

@LilWolfy Yeah those are lists.

What you'll end up doing is creating a list of all the words you want to pick from, then use a function called random.choice() to select one of those words.

LilWolfy

@SixBeeps ok thx