Skip to content

Instantly share code, notes, and snippets.

@gunnarig
Created September 24, 2018 14:26
Show Gist options
  • Save gunnarig/e464648abbd71fea65644c440d043772 to your computer and use it in GitHub Desktop.
Save gunnarig/e464648abbd71fea65644c440d043772 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:
if continue_ask:
continue_ask: True
breakit = input("continue:")
elif breakit == "y":
continue_ask = False
elif breakit =="n":
break
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)
continue_ask = True
#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