That just converts it to a string. Better to format it {:.0f}.format()
Here’s a piece of code I just finished. I might add some more things but at a good stopping point. I like to think that I am getting better. I made a real effort to include notes and full names so others can figure out what I am doing. Eventually I want to build a portfolio on GitHub.
#[0] #[1] #[2]
Copy and paste it in and let me know what you think. This is my 6th project so if anyone has improvement suggestions please let me know
# Budget Calculator based on 50/30/20
# A fun project to play with
# Define each calculation to make it modular, organized, and reusable
def savings_calculation(income):
return income * 0.2
def yearly_savings_calculation(income):
return (income * 12) * 0.2
def emergency_savings_calculation(income):
return (income * 0.8) * 6
def emergency_savings_months_calculation(income):
return ((income * 0.8) * 6) / (income * 0.2)
def essential_expenses_calculation(income):
return income * 0.5
def non_essential_expenses_calculation(income):
return income * 0.3
def inflation_loss_calculation(income):
return (income * 12) * 0.06
def calculate_debt_payment(debt, income):
return debt / (income * 0.2)
# Introduction Output
print("This is a simple program that explores what a 50/30/30 budget would look like for you.")
print("This is not intended as financial advice, only a educational tool.")
print(" ")
# Get input for monthly income
# loop to insure number input only
while True:
try:
income = int(input("What is your monthly take home income? $"))
except ValueError:
print("Invalid response. Please enter a number only.")
else:
break
# Calculations
savings = savings_calculation(income)
yearly_savings = yearly_savings_calculation(income)
emergency_savings = emergency_savings_calculation(income)
emergency_savings_months = emergency_savings_months_calculation(income)
essential_expenses = essential_expenses_calculation(income)
non_essential_expenses = non_essential_expenses_calculation(income)
inflation_loss = inflation_loss_calculation(income)
# Output print
print(" ")
print("Your monthly expenses for essential expenses should not exceed: ${:.2f}".format(essential_expenses))
print("Essential expenses would be food, housing, utilities, things of this nature.")
print(" ")
print("Your monthly spend on non-essential expenses should not exceed: ${:.2f}".format(non_essential_expenses))
print("Non-essential expenses would be cable tv, subscription services, fun and entertainment, things of this nature")
print(" ")
print("Your monthly target for savings and debt payment: ${:.2f}".format(savings))
print(" ")
print("You will save: ${:.2f} this year by following this plan".format(yearly_savings))
print("Your loss in purchasing power due to inflation this year is: ${:.2f}".format(inflation_loss))
print(" ")
print("Your emergency savings goal is: ${:.2f}".format(emergency_savings))
print("It will take you {:.0f} months to reach this goal by using your monthly target for savings and debt payment".format(emergency_savings_months))
print(" ")
# Debt input and tree
# loop to insure yes or no input only
while True:
try:
debt_question = input("Do you have debt? yes or no? ")
if debt_question.lower() == 'no':
print("Great Job!")
elif debt_question.lower() == 'yes':
debt = int(input("How much total debt do you have? $"))
debt_payment = calculate_debt_payment(debt, income)
print("It will take you {:.0f} months to pay this off using your monthly target for savings and debt payment.".format(debt_payment))
else:
raise ValueError("Invalid response. Please enter yes or no only.")
except ValueError as e:
print(e)
else:
break
Yes. What he said. Ubuntu on VM would be Linux
Everyone says it but it works. Use ChatGPT to learn the code you want to learn.
Enter the prompt or something similar: act as a tutor. Give me a lesson plan starting from zero to learn (code you want). Include a timeline and a list of resources. I can devote (x time, x number of days a week) to learn.
Whatever it gives you ask for a day by day breakdown etc.
Read the resources, learn the syntax. Each concept you get introduced to ask the AI to suggest a practice problem that uses X concepts. Etc repeat
I use Pycharm on a Linux machine
Is anyone familiar with either of these udemy courses?
100 Days of Code: The Complete Python Pro Bootcamp for 2023
or
The Python Mega Course: Learn Python in 60 Days with 20 Apps
A wife’s greatest fear is that somewhere, somehow, their husband is enjoying himself.
Cypherpunks write code.
Happy Easter Nostr 🐇 🐣
What determines what node a node connects to? I’m watching the traffic and it looks like random pings to different addresses, a small update with the latest block from this one, but then a large batch of data to another node that must have been offline for a few hours.
Dafuq is happening?
Only have to mess up once 😉
I’m always too scared to hunt wild mushrooms and eat them
(Historical Fiction) The Painted Bird by Jerry Kosinski
(Spiritual Philosophy)The Corpus Hermeticum and The Definitions of Hermes Trismegistus to Asclepius
(SCI-fi) Eon by Greg Bear
(Bitcoin) Everything Divided by 21 Million by Knut Svanholm
Not sure on libertarian fiction
What am I looking at?
Alright, this is about the best I can do with what little I know. Final version of this practice exercise and then I need to read and study more before I try another project. I’m happy with it being only my second coding attempt.
If any experienced python coders want to critique my code it would be appreciated. I know there is probably easier and cleaner ways than what I did.
# Savings Goal 5.0, Final 4th Practice Problem with additions
# define a function for annual savings calculation
def savings_goal(salary):
savings = salary * 0.2
return savings
# set input field for annual salary
print("You should be saving!")
print("A good target is 20%.")
print(" ")
salary_input = float(input("What is your annual salary? "))
savings = savings_goal(salary_input)
print("Your annual savings goal is $" +str(savings)) #output
# define a function for a percheck savings amount
def percheck_target(savings, monthly):
percheck = savings / (monthly * 12)
return percheck
# set input field for number of pay periods per month
print(" ") # is there a better way to add a space?
monthly_input = float(input("How many times do you get paid a month? "))
percheck = percheck_target(savings, monthly_input)
print("You should save: $" + str(percheck) + " per paycheck") #output
print(" ") # is there a better way to add a space?
# TRUTH BOMB
def wealth_steal(savings):
steal = savings - (savings * (1-0.06))
return steal
steal = wealth_steal(savings)
conditional_statement = input("Do you want to save in Bitcoin or Fiat? ")
if conditional_statement == "Fiat":
print("You will lose: $" + str(steal) + " this year due to inflation.")
print("Maybe you should save in bitcoin.")
print(" ")
conditional_statement = input("Do you want to save in Bitcoin or Fiat? ")
elif conditional_statement == "fiat":
print("You will lose: $" + str(steal) + " this year due to inflation.")
print("Maybe you should save in bitcoin.")
print(" ")
conditional_statement = input("Do you want to save in Bitcoin or Fiat? ")
if conditional_statement == "Bitcoin":
print("You will gain: $" + str(steal) + " this year over inflation by saving in Bitcoin.")
print("Fiat is a shitcoin.")
elif conditional_statement == "bitcoin":
print("You will gain: $" + str(steal) + " this year over inflation by saving in Bitcoin.")
print("Fiat is a shitcoin.")
else:
print("What are you stupid.")
Thank you. I haven’t done a IF statement yet so this was good learning for me. Here is v4.0
Ok I figured out how to take a video of it running. A little twitchy from my video card but here it is
