Python percentage calculator [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
3
down vote

favorite












I'm learning Python for 2 months now and I'm working on a little exercise app calculating percentages. I'd like to ask for a code review and comments. I'd like to make sure I'm following the right habits from the beginning.



# coding: utf-8

# In[9]:


def percA(perc, num):
perc_a = perc/100 * num
return perc_a

def percB(first, second):
percB = first/second*100
return percB

def percC(old, new):
percC = (new - old)/old*100
return percC

def percD(num, perc):
perc = perc/100
percD = num * (1 + perc)
return percD

def percE(num, perc):
perc = perc/100
percD = num * (1 - perc)
return percD

print("**************************************")
print("************** WELCOME ***************")
print("**************************************")
print("n")
choose = input("Choose option:nA. X% of YnB. X is what percent of YnC. By what percentage a number increased?nD. Add percent to a numbernE.Substract percentage from a numbernYour answer: ")
if choose.isupper() == True:
choose = choose.lower()
while choose == "a":
if "a":
usrperc = int(input("Provide percentage: "))
usrnum = int(input("Provide number: "))
result = percA(usrperc, usrnum)
print("0% of 1 is 2".format(usrperc, usrnum, result))
break
elif "b":
usrperc = int(input("Provide percentage: "))
usrnum = int(input("Provide number: "))
result = percA(usrperc, usrnum)
print("0% of 1 is 2".format(usrperc, usrnum, result))
break
else:
print("Choose from range A - E")






share|improve this question













closed as off-topic by Dannnno, Stephen Rauch, Imus, Sam Onela, Ludisposed Apr 30 at 17:40


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Dannnno, Stephen Rauch, Imus, Sam Onela, Ludisposed
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2




    Your code does not work as intended. The if "b" branch is never run. And if I choose "b", nothing happens.
    – Roland Illig
    Apr 29 at 7:43
















up vote
3
down vote

favorite












I'm learning Python for 2 months now and I'm working on a little exercise app calculating percentages. I'd like to ask for a code review and comments. I'd like to make sure I'm following the right habits from the beginning.



# coding: utf-8

# In[9]:


def percA(perc, num):
perc_a = perc/100 * num
return perc_a

def percB(first, second):
percB = first/second*100
return percB

def percC(old, new):
percC = (new - old)/old*100
return percC

def percD(num, perc):
perc = perc/100
percD = num * (1 + perc)
return percD

def percE(num, perc):
perc = perc/100
percD = num * (1 - perc)
return percD

print("**************************************")
print("************** WELCOME ***************")
print("**************************************")
print("n")
choose = input("Choose option:nA. X% of YnB. X is what percent of YnC. By what percentage a number increased?nD. Add percent to a numbernE.Substract percentage from a numbernYour answer: ")
if choose.isupper() == True:
choose = choose.lower()
while choose == "a":
if "a":
usrperc = int(input("Provide percentage: "))
usrnum = int(input("Provide number: "))
result = percA(usrperc, usrnum)
print("0% of 1 is 2".format(usrperc, usrnum, result))
break
elif "b":
usrperc = int(input("Provide percentage: "))
usrnum = int(input("Provide number: "))
result = percA(usrperc, usrnum)
print("0% of 1 is 2".format(usrperc, usrnum, result))
break
else:
print("Choose from range A - E")






share|improve this question













closed as off-topic by Dannnno, Stephen Rauch, Imus, Sam Onela, Ludisposed Apr 30 at 17:40


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Dannnno, Stephen Rauch, Imus, Sam Onela, Ludisposed
If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2




    Your code does not work as intended. The if "b" branch is never run. And if I choose "b", nothing happens.
    – Roland Illig
    Apr 29 at 7:43












up vote
3
down vote

favorite









up vote
3
down vote

favorite











I'm learning Python for 2 months now and I'm working on a little exercise app calculating percentages. I'd like to ask for a code review and comments. I'd like to make sure I'm following the right habits from the beginning.



# coding: utf-8

# In[9]:


def percA(perc, num):
perc_a = perc/100 * num
return perc_a

def percB(first, second):
percB = first/second*100
return percB

def percC(old, new):
percC = (new - old)/old*100
return percC

def percD(num, perc):
perc = perc/100
percD = num * (1 + perc)
return percD

def percE(num, perc):
perc = perc/100
percD = num * (1 - perc)
return percD

print("**************************************")
print("************** WELCOME ***************")
print("**************************************")
print("n")
choose = input("Choose option:nA. X% of YnB. X is what percent of YnC. By what percentage a number increased?nD. Add percent to a numbernE.Substract percentage from a numbernYour answer: ")
if choose.isupper() == True:
choose = choose.lower()
while choose == "a":
if "a":
usrperc = int(input("Provide percentage: "))
usrnum = int(input("Provide number: "))
result = percA(usrperc, usrnum)
print("0% of 1 is 2".format(usrperc, usrnum, result))
break
elif "b":
usrperc = int(input("Provide percentage: "))
usrnum = int(input("Provide number: "))
result = percA(usrperc, usrnum)
print("0% of 1 is 2".format(usrperc, usrnum, result))
break
else:
print("Choose from range A - E")






share|improve this question













I'm learning Python for 2 months now and I'm working on a little exercise app calculating percentages. I'd like to ask for a code review and comments. I'd like to make sure I'm following the right habits from the beginning.



# coding: utf-8

# In[9]:


def percA(perc, num):
perc_a = perc/100 * num
return perc_a

def percB(first, second):
percB = first/second*100
return percB

def percC(old, new):
percC = (new - old)/old*100
return percC

def percD(num, perc):
perc = perc/100
percD = num * (1 + perc)
return percD

def percE(num, perc):
perc = perc/100
percD = num * (1 - perc)
return percD

print("**************************************")
print("************** WELCOME ***************")
print("**************************************")
print("n")
choose = input("Choose option:nA. X% of YnB. X is what percent of YnC. By what percentage a number increased?nD. Add percent to a numbernE.Substract percentage from a numbernYour answer: ")
if choose.isupper() == True:
choose = choose.lower()
while choose == "a":
if "a":
usrperc = int(input("Provide percentage: "))
usrnum = int(input("Provide number: "))
result = percA(usrperc, usrnum)
print("0% of 1 is 2".format(usrperc, usrnum, result))
break
elif "b":
usrperc = int(input("Provide percentage: "))
usrnum = int(input("Provide number: "))
result = percA(usrperc, usrnum)
print("0% of 1 is 2".format(usrperc, usrnum, result))
break
else:
print("Choose from range A - E")








share|improve this question












share|improve this question




share|improve this question








edited Apr 28 at 20:29









Phrancis

14.6k644137




14.6k644137









asked Apr 28 at 17:35









Bart

162




162




closed as off-topic by Dannnno, Stephen Rauch, Imus, Sam Onela, Ludisposed Apr 30 at 17:40


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Dannnno, Stephen Rauch, Imus, Sam Onela, Ludisposed
If this question can be reworded to fit the rules in the help center, please edit the question.




closed as off-topic by Dannnno, Stephen Rauch, Imus, Sam Onela, Ludisposed Apr 30 at 17:40


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Dannnno, Stephen Rauch, Imus, Sam Onela, Ludisposed
If this question can be reworded to fit the rules in the help center, please edit the question.







  • 2




    Your code does not work as intended. The if "b" branch is never run. And if I choose "b", nothing happens.
    – Roland Illig
    Apr 29 at 7:43












  • 2




    Your code does not work as intended. The if "b" branch is never run. And if I choose "b", nothing happens.
    – Roland Illig
    Apr 29 at 7:43







2




2




Your code does not work as intended. The if "b" branch is never run. And if I choose "b", nothing happens.
– Roland Illig
Apr 29 at 7:43




Your code does not work as intended. The if "b" branch is never run. And if I choose "b", nothing happens.
– Roland Illig
Apr 29 at 7:43










1 Answer
1






active

oldest

votes

















up vote
1
down vote













You can call chose.lower without the if statement without any consequences as far as I know. I don’t have any experience with using something like while choose ==“a”, bit it looks to me like if choose ==“a” would work just the same way, and be more readable.






share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    You can call chose.lower without the if statement without any consequences as far as I know. I don’t have any experience with using something like while choose ==“a”, bit it looks to me like if choose ==“a” would work just the same way, and be more readable.






    share|improve this answer

























      up vote
      1
      down vote













      You can call chose.lower without the if statement without any consequences as far as I know. I don’t have any experience with using something like while choose ==“a”, bit it looks to me like if choose ==“a” would work just the same way, and be more readable.






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        You can call chose.lower without the if statement without any consequences as far as I know. I don’t have any experience with using something like while choose ==“a”, bit it looks to me like if choose ==“a” would work just the same way, and be more readable.






        share|improve this answer













        You can call chose.lower without the if statement without any consequences as far as I know. I don’t have any experience with using something like while choose ==“a”, bit it looks to me like if choose ==“a” would work just the same way, and be more readable.







        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Apr 29 at 0:18









        user168431

        111




        111












            Popular posts from this blog

            Chat program with C++ and SFML

            Function to Return a JSON Like Objects Using VBA Collections and Arrays

            Will my employers contract hold up in court?