Couple of lines of code for saving money.

I saw a post the other day on Instagram from a couple saving for a deposit for a house. What they have done is get a pack of 100 envelopes, write on them 1, next envelope 2, all the way up until each envelope has a number. Each week they each pick an envelope and put that amount of cash into that envelope. When they are all done you will have £5,050.

Now you may want to adjust this so it will be one a week for each week of the year, so 52 envelopes, you will still save £1,378 over the year. Could get more adventurous, do it each day, for each day of the month, based on 31 days you will save £496 a month, not too bad.

Anyway like my previous post on automated savings, I have written some code that will pick a random number from 1 to 100 and flash that up on the screen, when I get that number I will transfer that amount into an account, not a bad way to save up for a holiday or something. This is part one, I will enhance this to text me each Saturday with the amount to save.

All you need is create a txt file called money.txt, and type in 1 to a 100 and save the file in the same location. Then copy the code below into money.py. This is rough code, took me about 10 mins, if you think this can be reduced please get in contact.

import random
lines = []
# Read the file into a list
with open("money.txt") as file:
    lines = [line.strip() for line in file]
# Print the numbers
for x in range(len(lines)):
    print lines[x],
# Select a random number
random_num = random.choice(lines)
print random_num
# Remove it from the list
lines.remove(random_num)

# Write the list back out with the number removed
with open('money.txt', 'w') as f:
    for item in lines:
        f.write("%s\n" % item)
Happy Birthday Apple

Happy Birthday Apple

Scam Call Alert - 07494 481900

Scam Call Alert - 07494 481900