Articles of the Week
Pubbies of the Week
How to Create a Lottery System Using Python
Categories: Tech | Pubby Cash Received:
Do you know what Powerball is? If you do not know what it is, it is a lottery game. The computer randomly generates a set of 5 numbers between 1 through 31, and you have to try to guess it. If you guess all the numbers right, you get a lot of money. But if you guess some of the numbers correctly, you get a fraction of the money. In this article, I will explain how to create a lottery system using python. First of all, we will make the guessing numbers 0 to 9. We will also make a set of 3 numbers. This will make it easier to guess the number. The first thing you want to do is to make a winning set of numbers. We also need to make a few guesses using a dictionary. Here is an example.
pool = {'andy':[(1,2,3),(2,3,4),(3,4,5)],'evan':[(1,7,3),(5,9,8),(4,3,7)]
win = [7,4,3]
After that, you need to make a few variables. Here is an example.
big_tickets_numb = 0 #how many grand prize tickets
big_winners = {} #who was the big winner or winners
small_tickets_numb = 0 #how many small prize tickets
small_winners = {} #who was the small winner or winners
big_pcts = {} #percentage of money the big winner gets
small_pcts = {} #percentage of money the small winner gets
After making a few variables, you need to start looping them, because you want it to check your guesses multiple times. To do this, use the a for loop. You can also make a match_count variable to see how many times your guesses matched the real answer. Here is an example.
for k in pool:
for j in range(len(pool[k])):
match_count = 0
for i in range(len(pool[k][j])):
if pool[k][j][i] in win:
match_count += 1
if match_count == 2:
small_winners[k] = small_winners.get(k,0) + 1
small_tickets_numb += 1
if match_count == 3:
big_winners[k] = big_winners.get(k,0) + 1
big_tickets_numb += 1
Then, you need to figure out how much percent each person gets if multiple people get the same winning value. To do this use an if statement followed by a for loop and then return those values. The big winner gets 80 percent of the money and the small winner get 20 percent of the money. But if two people both get the big money or the small money, then we must divide them equally. Here is an example.
if small_winners:
for k in small_winners:
small_pcts[k] = small_winners[k]*0.2/small_tickets_numb
if big_winners:
for k in big_winners:
big_pcts[k] = big_winners[k]*0.8/big_tickets_numb
return small_winners,small_pcts,big_winners,big_pcts
Finally, put all of what you just did into a function and then print it. Here is an example.
def lottery_winner(pool, win):
#Put everything you just did right here
small_winners,small_pcts,big_winners,big_pcts = lottery_winner({'Evan':[(1,2,3)]},[1,2,3])
print(small_winners,big_winners)
print(small_pcts,big_pcts)
If you did all of that, you should have a working lottery system....
Read more
Mapping IP addresses to Geographic Locations in Python
Categories: Tech | Pubby Cash Received:
An IP address - a list of four segments of 3 digits numbers between 0 and 255 and connected by dots can contain more information than you think. Underneath this article, you can see where this article is posted from. This gives you an example that an IP address can be transformed to the geographical location.
I'm introducing one way to realize it in Python - use API from ipinfo.io. Their free version can give the geographic location, ISP provider's name, and even GPS coordinates of the location, which should be enough for most website owners. Their API include a token, which is good for querying 50,000 times a month. The following code can be used as an example. Remember to replace the ip and token with your ip and token.
import requests, json
link = f'https://ipinfo.io/{ip}?token={token}'
r = requests.get(link)
content = json.loads(r.content)
print(content)
...
Read more
Is your password slacking?
Categories: General, Tech | Pubby Cash Received:
We are living in an advanced world, where we make practically any sort of exchange utilizing the Internet. Passwords are a piece of our regular day to day existence, particularly with regards to email and online life accounts. How might you feel if the entirety of the cash in your financial balance was taken? Maybe you need a more grounded secret word. The security arrangements of a significant number of sites leave data totally uncovered. Consistently, individuals build up another program or new strategy to break our security. There are articles that clarify how a programmer can break your record secret key effectively, simply utilizing an assortment of projects like a basic secret phrase speculating program. This program makes different speculations until the secret word is completely split. The program may take a couple of moments or a century; it relies upon the multifaceted nature of the secret key. Different techniques like key lumberjacks comprise of equipment gadgets joined to your PC that can duplicate your data through watchwords that you use to get to the records. Hacking through telephones is another route for these individuals to take your information. Utilizing programs that can copy what you see on your telephone, it is moderately simple for them to get your secret phrase from your telephone.... Read more
How to make people at a higher level access more information than ones at a lower level using Python.
Categories: Tech | Pubby Cash Received:
Do you know how to people at a higher level access more information than ones at a lower level using Python? Well, if you do not know how, here is a way to do it. Let's say that you want people above level 4 to access other user's locations, but not people below level 4. You can do this by making two parts. For example, one could be info and the other one could be info_m. The info means what people below level 4 see and info_m means what people above level 4 see. Then you would assign each one their value. Here is an example. info = f"{content['region']} {content['country']}" info_m = content Once you did that, you can go to your HTML. In your HTML, use an if statement and an else statement. Here is an example. if level > 4 print(info_m) else print(info) After that, save your code by pressing the Ctrl and the S key at the same time. Finally, run your code.... Read more
What is an IP address
Categories: Tech | Pubby Cash Received:
Do you know what an IP address is? Well, the IP address stands for internet protocol address. An IP address is 4 or 6 groups of numbers separated by a period. A group of 4 numbers is known as IPv4 and a group of 6 is known as IPv6. Each group of numbers must be between 0 and 255. For example, 123.123.123.123 is a valid one, but 321.321.321.321 is not. This is because 321 is greater than 255. You might be wondering what an IP address does. Well, it is a tool made for devices so they can connect to a computer network that uses the Internet Protocol for communication. It can also be used to track your physical location.... Read more