I am trying to write a method that generates and returns n random points in a 2-dimensional space given the width and height in Python I coded an algorithm but I want to recieve float points in the system.
Here my code is:
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)]
How can I print them as float. For example: (8.75 , 6.31)
Thanks a lot for the help.
Source: Python Questions