“Python Nombre aléatoire” Réponses codées

Nombre aléatoire Python

# generate random integer values
from random import randint

value = randint(0, 10)
print(value)
Successful Stoat

Python Nombre aléatoire

from random import randint

print(randint(1,3))

#Possible Outputs#
#1
#2
#3
DatMADCoder

Python Nombre aléatoire

### random number between 0 and 0.99999
print(random.random())

### random number between 5 and 8
print(random.uniform(5,8))

### random number with normal distribution (bell curve)
## random.normalvariate(standard deviation sigma)
print(random.normalvariate(5, 0.1))

### simulate dice roll
print(random.randint(1,6))

### random item from list
number = ['one', 'two', 'three']
print(random.choice(number))
AttractivePenguin

Python Nombre aléatoire

import random  
#random numbers from 1 to 10
print(random.randint(1,10)) #use of random.randint()

#random word from a list
print(random.choice(["a","b","c","d","e"])) #use of random.choice()

#random shuffle a list
random_list = ["a","b","c","d","e"]
random.shuffle(random_list) #use of random.shuffle()
print(random_list)
Nishant Tiwari

Python Nombre aléatoire

import random # Imports the random package so that the program has full access to random-based functions

start = 1 # Put your staring value here

end = 8 # Put your ending value here

number = random.randint(start, end) # Calls the randomint function of  random to generate a random number

print(number) # Prints the number that was generated above
aguy11

Python Nombre aléatoire

import random
# Random number, 0 through 10, INCLUDING 10:
print(random.randint(0, 10))

#Random number, 0 through 10, NOT INCLUDING 10:
print(random.randrange(0, 10))

#Random choice from a list:
my_list = ["Apples", "Oranges", "Watermelon", "Pineapple", "Grapes"]
print(random.choice(my_list))

# Set a custom seed of 10 for random to work with:
random.seed(10)
Nolan Barker

Réponses similaires à “Python Nombre aléatoire”

Questions similaires à “Python Nombre aléatoire”

Plus de réponses similaires à “Python Nombre aléatoire” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code