Y
Y
YUKKKURI2020-04-30 19:40:11
Python
YUKKKURI, 2020-04-30 19:40:11

How to make the random operator accept a range of numbers from the user?

For example, we take the variable n and assign it a random value from 1 to 5:

import random
n = random.randint (1, 5)

How to make sure that this same range is set by the user when starting the program?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Pokrovsky, 2020-04-30
@YUKKKURI

Have you tried learning Python?

import random
a = int(input())
b = int(input())
n = random.randint (a, b)

N
Nikita Yaremenko, 2020-05-01
@nyar_roller

Or like this:

import random

n = random.randint (int(input()),int(input()))
In this case, two numbers will be entered from a new line ..
Or like this:
import random

rng = input().split()

rng = [int(i) for i in rng]

n = random.randint (rng[0], rng[1])
In such a number will be written in one line separated by a space

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question