Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
1

halp me pls

LilWolfy
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

1 year ago

Voters

Comments

TopNew
1
SixBeeps
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?

1 year ago
1
LilWolfy
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)

1 year ago
1
SixBeeps
SixBeeps

@LilWolfy
Real quick, are you familiar with lists?

1 year ago
1
LilWolfy
LilWolfy

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

1 year ago
1
SixBeeps
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.

myNeatWords = ['words', 'palabras', 'mots'] x = random.choice(myNeatWords) print(x)
1 year ago