Wednesday, July 1, 2020

Simple Python program to calculate profit percentage

Filename: Profit.py  // written in Notepad

***********File begins here****************

// function definition
def findProfit():
    x = 'a'
    while x != 'n' or x != 'N':
        c = float(input("Enter current market price : "))
        s = float(input("Enter expected sell price : "))
        a = float((s - c)/c)*100
        formatted_a = "{:.2f}".format(a)
        print("% Profit for buy at " + str(c) + " and expected sell at " + str(s) + " would be : " + str(formatted_a) +"%") 
        print()   
        x= input("Want to continue (y/n) :") 
        if x == 'n':
            exit()

//call the function to execute it
findProfit()

***************File ends here**************

Outputs % profit upto 2 decimal points.

Sacred Thought

26 April 2024  Dear friends, I write the explanation of two verses of Geets for all of you, I hope you all will like it and benefit from it....