I created a code that was supposed to determine how well my system of guessing is. The scenario is that there is n amount of tanks. Each tank is uniquely numbered 1 to n. Seven of these tanks are captured so we only know their serial number (This is done by getting a random number from 1 to n for each of the seven tanks). I am supposed to predict n based on those serial numbers. My method (the one I have to code) was to first find the max number in the list and the number three standard deviations above the mean of the list. Then, I get my own random numbers from 1 to n where n ranges from the max number and the three standard deviations number. During this time, I calculate the standard deviation for each of the seven serial numbers generated and after all of the standard deviations are calculated, I find which one is closest to the standard deviation of the original list. Whichever one is the closest to the standard deviation would constitute as my guess for n. I repeat this process as many times as necessary (the more times the more accurate results) to generate a list of guesses. My final guess then would be the mean of that list. My code is below:
import random import statistics chosenNum = 429 #n is given only to check how well our process works numRuns = 100 #number of guesses - my teacher wants at least 100 numCorrect = 0 numGuessN =  guesses =  percentErrors =  for x in range(numRuns): randNum = [random.randint(1,chosenNum + 1),random.randint(1,chosenNum + 1),random.randint(1,chosenNum + 1),random.randint(1,chosenNum + 1),random.randint(1,chosenNum + 1),random.randint(1,chosenNum + 1),random.randint(1,chosenNum + 1)] #generates the seven serial numbers. NumSTD = statistics.stdev(randNum) #standard deviation maxNumSTD = statistics.mean(randNum)+(3*(statistics.stdev(randNum))) #three standard deviations above the mean maxNum = max(randNum) #max number in list #print (NumSTD) #print (maxNumSTD) #print (maxNum) #print (randNum) for x in range(200): #the greater the range, the more accurate the results STDarray =  if (maxNum - maxNumSTD < 0): for y in range(maxNum,int(maxNumSTD)): #n is max number to max number from Standard Deviation randNumZwei = [random.randint(1,y),random.randint(1,y),random.randint(1,y),random.randint(1,y),random.randint(1,y),random.randint(1,y),random.randint(1,y)] #my simulated serial numbers testNumSTD = statistics.stdev(randNumZwei) STDarray.append(testNumSTD) else: for y in range(int(maxNumSTD),maxNum): randNumZwei = [random.randint(1,y),random.randint(1,y),random.randint(1,y),random.randint(1,y),random.randint(1,y),random.randint(1,y),random.randint(1,y)] testNumSTD = statistics.stdev(randNumZwei) STDarray.append(testNumSTD) for z in range((len(STDarray) - 1)): if((min(STDarray, key=lambda x:abs(x-NumSTD))) == STDarray[z]): #find closest number to original standard deviation numGuessed = z + maxNum numGuessN.append(numGuessed) #make a list of all the guessed numbers guess = int(statistics.mean(numGuessN)) #the final guess is simply mean of all the other guesses generated #print(guess) guesses.append(guess) #number of final guesses should be the same as number of trials print ("Your guesses are: " + str(guesses)) for x in range(len(guesses) - 1): percentError = (abs(guesses[x] - (chosenNum))/float(chosenNum)) * 100 percentErrors.append(percentError) if(guesses[x] == chosenNum): numCorrect = numCorrect + 1 else: closestNumber = min(guesses, key=lambda x:abs(x-chosenNum)) averagePercentError = statistics.mean(percentErrors) print ("The average Percent Error is: " + str(averagePercentError) + "%") if (numCorrect > 0): print ("You got the correct number " + str(numCorrect/float(len(guesses)))) else: print ("Your closest number was: " + str(closestNumber))
This code works but takes way too long to give me my result. The whole point of this is to calculate accuracy but not take way too long. How can I make this code more efficient to run faster.
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!