22 lines
571 B
Plaintext
22 lines
571 B
Plaintext
Question 17:
|
|
Write a Python program to accept cost price and selling price, then print whether there is profit, loss, or no gain.
|
|
|
|
Answer:
|
|
def main(cost_price: float, selling_price: float) -> None:
|
|
if selling_price > cost_price:
|
|
print(f"Profit: {selling_price - cost_price}")
|
|
elif selling_price < cost_price:
|
|
print(f"Loss: {cost_price - selling_price}")
|
|
else:
|
|
print("No gain, no loss.")
|
|
|
|
if __name__ == '__main__':
|
|
main(100.0, 120.0)
|
|
main(150.0, 130.0)
|
|
main(200.0, 200.0)
|
|
|
|
Output:
|
|
Profit: 20.0
|
|
Loss: 20.0
|
|
No gain, no loss.
|