Python percentage calculator [closed]
Clash 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")
python beginner calculator
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
add a comment |Â
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")
python beginner calculator
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
2
Your code does not work as intended. Theif "b"
branch is never run. And if I choose "b", nothing happens.
â Roland Illig
Apr 29 at 7:43
add a comment |Â
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")
python beginner calculator
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")
python beginner calculator
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
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
2
Your code does not work as intended. Theif "b"
branch is never run. And if I choose "b", nothing happens.
â Roland Illig
Apr 29 at 7:43
add a comment |Â
2
Your code does not work as intended. Theif "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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
answered Apr 29 at 0:18
user168431
111
111
add a comment |Â
add a comment |Â
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