Quel est la fonction utilisée pour afficher un nom aléatoire formé par 8 lettres ?? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 2

Quel est la fonction utilisée pour afficher un nom aléatoire formé par 8 lettres ??

11th Oct 2020, 7:18 PM
Nõūr El Hōuda
Nõūr El Hōuda - avatar
2 Réponses
+ 2
Quelque chose comme celui-ci? from random import sample as s print("".join(s([chr(c) for c in range(97, 123)], 8)))
12th Oct 2020, 4:00 AM
David Ashton
David Ashton - avatar
0
Comment voulez-vous sélectionner ces 8 lettres? 1) vous pouvez prendre des lettres a-z dans une chaîne ou une liste, ou n'importe quelle collection. Sélectionnez ensuite un caractère aléatoire de la collection en générant un nombre aléatoire comme for i in range(8): print (int (random.random ()*10)) 2) random.choice (une liste d'éléments) que vous pouvez utiliser pour sélectionner un choix dans la liste d'options. De nombreuses façons, essayez d'abord une méthode et postez une tentative si vous avez frappé. (translated this) How you want select those 8 letters? 1)you can take a-z letters into a string or list,.. Then select a random character from the collection by generatorating a random number as for i in range(8): print(int(random.random()*10)) 2)random.choice(a list of elements) you can use to select 1 from the list. Many ways, try a method and post attempt if you struck. Edit: simple example: share yours import random as r for i in range(8): print(chr(int(r.random()*26)+97),end="")
11th Oct 2020, 7:45 PM
Jayakrishna 🇮🇳