Elder Moderator

[email protected]

Total likes received: 94 | Pubby Cash: 873


Evan is a person who does coding. He codes with Python and watches videos of bootstrap. That's it.

Articles Liked by Me: 53

This Data Structure Is Underrated!

Categories: General, Tech | Pubby Cash Received:  0

Let’s say that you needed to create a list of all the users that have been banned on your site. Many programmers would just use a list, and that’s just fine. They would insert a tuple containing information about the first user and the time banned, then continue with the second user and their time banned, and so on. If they want to remove a user from the list, they could either use ‘pop’ or ‘remove’. Additionally, if they want to update an item in a list, it can be very difficult because there might be multiple items with the same name. Basically, using a list isn’t the best way to go when it comes to storing lots of data that is easily accessible. So is there an even easier way? The answer is yes. Dictionaries are very beneficial in this situation because each item stored in a dictionary is unique. If you want to remove an item from a dictionary, all you have to do is find the key and delete it using the ‘del’ keyword followed by the name of the key. It’s that simple. And if you want to update an item in a dictionary, you can simply call that item using it’s key and set that to your new value. Many programmers underestimate the power of dictionaries and often turn to lists because dictionaries are just a little more confusing. But trust me, once you get the hang of dictionaries, storing data will feel like a breeze....  Read more

Be a Trader in Real Stock Market with Your Pubby Cash

Categories: Tech | Pubby Cash Received:  0

Stock trading is about economics. This is also a skill that one definitely needs to master in the modern world. I'm glad to find that the GoPubby stock trading market is online. You have a selection of trading over 20 stocks with your Pubby Cash. The stocks on the market right now are choices of brand company names covering a variety of sections including technology, consumer goods, health, finance, energy, transportation, utilities, and so on. The reason I say this is real stock market is because you will be trading at real-time stock prices. For example, one share of Facebook stock costs 240 right now, you will be able to buy it at 240, and of course, the currency is not in US Dollars, but in Pubby Cash. After refreshing the page, if the stock price changed, your net worth will increase or decrease. You will gain or lose Pubby Cash only at the moment the stocks are sold. The recommendation is if you see the price of the stock you are holding decreases at a moment, keep holding it, unless you urgently need Pubby Cash at that moment. Be confident in the US economy! The overall trend of investment should make you gain money in the long run. A side note: Without Pubby Cash at a whole number multiple of one share price will not forbid you from buying that stock. Feel free to use a fractional number, no matter how small it is. You also don't need to invest all your Pubby Cash into the same company. You can split your Pubby Cash into multiple investments, which simulates S&P500 and can greatly lowers your investment risks. Have fun in the GoPubby Stock Market! ...  Read more

Is IDLE Good?

Categories: General, Tech | Pubby Cash Received:  10

It comes pre-installed with Python, but many coders just ignore it. Is IDLE worth your time? Well, if you’re a beginner, IDLE would be a great start for you. Although it has just the bare bones, the best place to experiment with Python code is in the interactive interpreter, otherwise known as a shell. The shell is a basic Read-Eval-Print Loop (REPL). It reads a Python statement, evaluates the result of that statement, and then prints the result on the screen. Then, it loops back to read the next statement. The Python shell is an excellent place to experiment with small code snippets. You can access it through the terminal or command line app on your machine, however, all of the text will be a single color and it will be hard to understand the outputs. You can simplify your workflow with Python IDLE, which will immediately start a Python shell when you open it. IDLE will automatically highlight the keywords and other python commands so you will know without a doubt what you are looking for. Every programmer needs to be able to edit and save text files. Python programs are files with the .py extension that contain lines of Python code. Python IDLE gives you the ability to create and edit these files with ease. Python IDLE also provides several useful features that you’ll see in professional IDEs, like basic syntax highlighting, code completion, and auto-indentation. Professional IDEs are more robust pieces of software and they have a steep learning curve. If you’re just beginning your Python programming journey, then Python IDLE is a great alternative!...  Read more

Write and Read a Dictionary into TXT file in Python

Categories: Tech | Pubby Cash Received:  0

I've been exploring an elegant way of exporting/importing a dictionary into/from an external TXT file for recording purposes. Say I have a dictionary with stocks codes and prices, and the dictionary's name is called stocks, and this dictionary is stored in a py file called rank.py. The txt file I've like to export to is 'stocks.txt'. The relative path from the operating py file to the txt file is 'static/stocks.txt'. To export the dictionary from the py file into the txt file, this code will be neat: from rank import stocks with open('static/stocks.txt', 'w') as f: print(stocks, file=f) To read the dictionary from the txt file, use this code: with open('static/stocks.txt', 'r') as f: content = f.read() stocks = eval(content) When it comes to the operation in flask route functions, I found it worked totally different with regard to the file path of the txt file. An error of "no file/file directory" keeps blowing off the code. Eventually I figured out that the file path should be written in a different way with the following code: import os from flask import current_app f_path = os.path.join(current_app.root_path, 'static/stocks.txt') with open(f_path, 'r') as f: content = f.read() stocks = eval(content) What a tricky debugging issue! ...  Read more

The Raffle Game

Categories: Tech | Pubby Cash Received:  10

It would be fun to find ways for pubbies to spend and earn Pubby Cash. Purchasing a raffle ticket is one of the ways the admin team has developed. Let me explain how this is realized. 1. Create a table in the database with sufficient columns to record all relevant raffle related information. The columns are: raffle id, date raffle opened, date raffle closed, current raffle pool, max raffle pool, transaction activities (a list with player id), winner id, and raffle status. The table should be declared as a model and linked to the code. 2. When a player trying to buy a raffle ticket, the database will be queried for the most recent game. If the most recent game is closed, a new game will be created. When the max raffle pool has reached (100 Pubby Cash) in this case, the status of the game will be changed to a closed state. Random number will be generated to determine who is the winner. 3. Update the database with relevant info. The tables that will be affected are the cash table, message table, user table, and of course the raffle game table. For the cash table, record the purchase transaction details. If a player wins, insert an additional transaction on the amount that he/she won. For the message table, update the table with a new message sent to the winner. For the user table, all players' Pubby Cash balance should be updated. For the raffle game table, the game record should be updated. 4. Generate a plot visualizing the dynamic purchasing activities of pubbies involved in the raffle game. This would require a data visualization module "matplotlib", which will generate a bar chart plotting the number of tickets each pubby purchased on the x axis, and the name of each pubby who purchased ticket(s). Then, a raffle game is all set to go! ...  Read more

1 ... 6 7 8 ... 11

Daily Deals


MECHANICSBURG WEATHER