mercredi 22 juillet 2020

How to generate a random order of numbers to a string based on conditions Python

How would you generate a random number string in Python based on the following conditions.

  1. The string must be between the length of 3 and 7
  2. The string must only contain numbers from 1-7
  3. The string must not have spaces

I tried the following for the string output but I am struggling with the conditionals

letters = string.digits
print ( ''.join(random.choice(letters) for i in range(10)) )

The output I received was:=

9432814671

If you could be kind enough to help me out and guide me I would be grateful to you.




Aucun commentaire:

Enregistrer un commentaire