Skip to content

Instantly share code, notes, and snippets.

@beltiras
Forked from gunnarig/ppp.py
Last active September 24, 2018 14:44
Show Gist options
  • Save beltiras/a47602cb8200f03ed81d100fc791ee6b to your computer and use it in GitHub Desktop.
Save beltiras/a47602cb8200f03ed81d100fc791ee6b to your computer and use it in GitHub Desktop.
from fractions import Fraction
# shares price
def sharesXprice(stock,valiue):
result = stock*valiue
divide = valiue % 1
dollar = int(valiue)
print("{0} shares with market price {1} {2} have valiue ${3}".format(shares,dollar,divide,result))
continue_ask = True
continue_ask = False
while True:
try:
shares = int(input("Enter number of shares: "))
except ValueError:
print("Invalid number!")
else:
try:
a,b,c = input("Enter price (dollars, numerator, denominator): ").split(" ")
price = Fraction(int(a),1)+Fraction(int(b),int(c))
except ValueError:
print("Invalid number!")
else:
sharesXprice(shares,price)
if input("Continue?") == "n":
break
#result = shares*price
#divide = price % 1
#dollar = int(price)
#print("{0} shares with market price {1} {2} have valiue ${3}".format(shares,dollar,divide,result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment