Most popular tags

304 questions

415 answers

71 comments

329 users

Most active Members
this week:

    how do i work out percentages in python??????

    +3 votes
    asked Oct 7, 2016 in Python by 14scotta (420 points)

    2 Answers

    0 votes
    Lets say you want to work out 15% of 200.   In maths you would use the following:

    200 * 15 / 100

    The 15/100 gives you the percentage.

     

    In python:

    amount = 200

    percentage = 15

    Value = amount * percentage / 100
    answered Oct 7, 2016 by smartin (10,750 points)
    0 votes

    I would reccomend doing something along the lines of:

     

    amount = float( input ("What is your amount?"))

    percentage = float( input ("What is the percentage you need"))

    value = amount * percentage / 100

    print ("Your answer is", value")

     

     

    float is the same as using the int command by allowing you to use your inputs in calculations. However, float allows the values to be decimals such as 3.2 or 0.24. Whilst the int option would just give you an error!

    I use inputs rather than manually giving the answer in code as in a larger program the user wouldnt have to enter the code. They can just run the program and get the desired answer. No hassle!

    This is very much like Mr Martin's solution I just thought this would help others (who don't know how to code) to use this easier.

    answered Oct 8, 2016 by anonymous
    Welcome to Selby Computing Q&A, where you can ask questions and receive answers from other students in Computer Science.
    ...