Computer Science, asked by priyanka6254, 5 months ago

wap to input the cost price and selling price of an article. Calculate and print the profit or loss. ​

Answers

Answered by jai696
3

\huge\red{\mid{\fbox{\tt{Using\: Python\: 3}}\mid}}

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))

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Answered by Equestriadash
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