J'essaie d'écrire une méthode qui génère et renvoie n points aléatoires dans un espace bidimensionnel donné la largeur et la hauteur en Python. J'ai codé un algorithme mais je veux recevoir des points flottants dans le système. Voici mon code :
import random
npoints = int(input("Type the npoints:"))
width = int(input("Enter the Width you want:"))
height = int (input("Enter the Height you want:"))
allpoints = [(a,b) for a in range(width) for b in range(height)]
sample = random.sample(allpoints, npoints)
print(sample)
Output is:
Type the npoints:4
Enter the Width you want:10
Enter the Height you want:8
[(8, 7), (3, 3), (7, 7), (9, 0)]
Comment puis-je les imprimer en tant que flottant. Par exemple : (8.75 , 6.31)
Merci beaucoup pour votre aide.