To calculate profit loss for given cost sell price in python program
Answers
Answered by
4
cp = float(input("cp: "))
sp = float(input("sp: "))
if sp > cp:
profit = sp - cp
profit_percent = (profit / cp) * 100
print(f"profit: {profit}\nprofit%: {profit_percent:.2f}")
else:
loss = cp - sp
loss_percent = (loss /cp) * 100
print(f"loss: {loss}\nloss%: {loss_percent:.2f}")
Similar questions