Intro:
Hey, what's up. I'm learning python (still...). I'm using 2.6.2 and running IDLE for the coding part. I've been following a very easy to follow tutorial on youtube to get me started. This is the 2nd time I've tried to start learning Python, but I feel much less confused so far and really am enjoy it.
Forgive me if I use the wrong coding terms, I'm still learning!
Anyway, my goal for myself this week is to produce a very simple, yet functional and useful (to me) program.
Problem:
I am writing a program to calculate how much a stock price must rise in order to meet your profit goal. It's pretty simple math. Basically, the program takes in the users cash they want to spend, price of stock, how much money they want to make 'profit' from the stock and any fees associated with the stock transaction (broker fees). It then tells them how much the stock must rise in price before they can sell and meet their profit goal.
Here's the code so far (minus all the math stuff, which will probably be posted later when/if I have problems with it)
cash=input("How much money do you want to spend? ")
stockprice=input("What is the share price of the stock? ")
cashgoal=input("How much money do you want to make as profit? ")
stockfees=input("What is the stock transaction fee (if applicable)? ")
print ""
print "This is how much money you have to spend: $%i" % cash
print "This is how much each share costs: $%i" % stockprice
print "This is how much you want to make: $%i" % cashgoal
print "This is how much each stock transaction costs: $%i" % stockfees
The problem I'm having is working with decimal numbers. For the stock price, if I use a number such as 0.179, when 'print' the info back to the user (this is just for testing purposes now) it returns a '0' value. But, this only happens when I print the info using a %i in the string. If I just print the integer without using the %i in the string:
print stockprice
Then it will return the correct value of '0.179'.
I'm missing the info on how to convert the 'stockprice' into something the %i can handle correctly. Or maybe I shouldn't be using %i for decimals...or maybe I need to take the 'stockprice' after the user has given input and convert it to something else before using the %i in the str.
Anyway, help please! :)
ps: what's the correct way to post formatted code? I used
and
, but I don't see what it did exactly.