mardi 26 janvier 2021

If statement that will generate 5 random numbers that sum to 210 and then write these numbers to excel openpyxl

I need to write a script that will generate 5 random whole numbers that sum up to 210 and then take these 5 generated numbers and write them to excel using openpyxl, the excel sheet will then check to see if a certain cell's content is less than a certain number and if it isn't then the program will run again until it checks out.

so far I have defined my workbook and worksheet in question I have tried the following to generate the random numbers

a = np.random.random(210)

a /= a.sum()

The numbers returned aren't whole numbers...that's the first problem.

My other problem is going to be storing the 5 random numbers in a way that I can use them with an if statement to write to my excel sheet.

I've written many scripts that interact with excel but I haven't tried to do anything like this where it will be constantly looping and checking and i'm a bit in over my head.

If you have any helpful info it would be very much appreciated!! Thank you!!




Aucun commentaire:

Enregistrer un commentaire