Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python
- import re
- '''
- Copyright 2017 profitgenerator
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- '''
- #------------------------------------------------------------------------------------------------
- file_name="test" # the name of the file containing the all the comments in one large text
- winner_number=4661 # the number that is the winner of the lottery
- f=open(file_name,"r") # read all the contents of the file into 1 string
- content = f.read()
- f.close()
- number_array=(re.findall('\d+', content )) # extract all numbers from the big text
- size=len(number_array)
- diffarray=[]
- for i in range(size): # calculate the difference between the winner number and their guess
- diffarray.append(abs(int(number_array[i])-winner_number))
- small_error= min(diffarray) # returns the smallest error guess
- for i in range(size): # return the number from the player's guess that match that small error
- if(diffarray[i]==small_error):
- winner_guess=number_array[i]
- break
- print "The winner guess is: "+winner_guess # return the guess closest to the winner number
- print "---------------------------------------------------------------------"
- print "Now search for this number in your comment box and see who wrote it, that person is the winner"
Advertisement
Add Comment
Please, Sign In to add comment