wap to input the cost price and selling price of an article. Calculate and print the profit or loss.
Answers
Answered by
3
def calc_pl(cp, sp):
pl = sp - cp
return f"profit: {pl}" if pl > 0 else f"loss: {pl}"
cp, sp = [float(n) for n in input("enter cp & sp: ").split()]
print(calc_pl(cp, sp))
Answered by
34
The following cσdes have been written using Python.
Source cσde:
op = float(input("Enter your original price: "))
sp = float(input("Enter your selling price: "))
if op > sp:
print("You have incurred a loss of", op - sp)
else:
print("You have incurred a profit of", sp - op)
We use the float() data type to retrieve the price since prices can be of decimal values and float indicates point values.
We then use an if-else structure, to test the expression and see if it renders according to the required output.
Similar questions