#๐Ÿ”’ need help with random module

53 messages ยท Page 1 of 1 (latest)

hollow cargoBOT
#

Hey @deep marten!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
#

@deep marten

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

deep marten
#

Im supposed to get this output of 10#25#15 but that's not really what I'm getting

#

And I don't understand about this program itself

#

import random

L = [5, 10, 15, 20, 25, 30]

for i in range(1, 3):
first = random.randint(1, 4) # Indices 1 to 4
second = random.randint(1, 4) # Indices 1 to 4
third = random.randint(1, 4) # Indices 1 to 4
print(L[first], L[second], L[third], sep='#')

drowsy hound
#

Since you're using random you can't really say "I'm supposed to get this exact output" because well, ...that's the whole point of random

deep marten
#

Im supposed to find the output

#

From like 4 options

fervent nexus
deep marten
fervent nexus
#

As Tathya pointed out though, you're dealing with randomness so you can't expect to get those exact results

deep marten
fervent nexus
#

Ok but it's random, you can't guarantee anything

deep marten
#

Oh

fervent nexus
#

Do you have an assignment sheet you were given with instructions?

deep marten
#

My teacher says you can get output with this information

#

Just that program

fervent nexus
#

You might get that output, but not everytime

deep marten
#

Oh

fervent nexus
#

Without knowing exactly what is being asked of you, it's hard to write code that meets those conditions

deep marten
#

But if that's the case all the 4 options could be correct right

fervent nexus
#

all possible outputs? Or just a few potential ones?

deep marten
fervent nexus
#

there's more than 2 possible outputs though

#

there's 64 of them

deep marten
#

What if it's jus a few potential ones?

fervent nexus
deep marten
fervent nexus
#

why?

deep marten
#

As it ends with #

#

You're using seperator

#

So it can't end with # right

fervent nexus
#

Yes, you're right

deep marten
#

Is there any mistake in option b or c tho

fervent nexus
#

Oh my mistake, there is only one correct answer then

deep marten
fervent nexus
#

Well your random int is only selecting whatever is in index 1-4

#

Do any of those have numbers found in other index positions?

fervent nexus
#

What numbers are found in index 1-4?

deep marten
#

10,15,20,25

fervent nexus
#

yes exactly

#

do any of the options have numbers that aren't those?

deep marten
#

Oh yeah b and c doesn't have

fervent nexus
#

๐Ÿ™‚

deep marten
#

Thank you so much!

hollow cargoBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.