Can you post the code or part of the code that you've tried because as per your given information I don't think there is a way of getting that weird answer
Hi all.
I'm trying to find a percentage of a number but getting a lot of weird answers.
I'm learning programming so I'll try and keep it in its format.
gdp = 100
spending = 5 (this is 5%, I want to be able to find how much this percentage is)
How would I do this? I've tried (gdp / spending) * 100 but that gave an answer like 0.0000033666.
Can someone please help?
Sorry if this is confusing, I'm just trying to figure out how to find how much money is in the percentage. Say the user inputs 30% of gdp spending, I'd like to figure out how much that 30% is.Code:gdp = 0 spending = 0 gdpinput = int(input("Enter your countries GDP: ")) This lets the user input the country's gdp spending = int(input("Enter the spending % of gdp (ex. 0.03 for 3%): ")) This asks the user to input the country's spending budget = (gdpinput / spending) * 100 This was my failed calculation print(budget)
Thanks
EDIT:
I think I've figured it out.
I changed
to thisCode:budget = (gdpinput / spending) * 100
Code:budget = (gdpinput * spending) / 100
If, say, gdpinput is in dollars, then (gdpinput * spending) is the dollar value of spending. I am not sure how to describe (gdpinput * spending) / 100 other than 1/100th of the dollar value of spending.
If spending is the actual fraction, say, 0.03, then spending * 100 is the same fraction expressed as percents; in this case, 3%. But if x is a dollar value, then x / 100 is in no way the same value.
Yes if the variable spending contains an actual fraction (not expressed in percents), which is what your code says.
Why don't you make several test input/output values and see if you code works correctly. Say, for your example in post #1 where gdp is 100 and spending is 0.05, what should the budget be?
That is correct. However, it is not clear how you enter 0.05%. Your code asks to enter it as a fraction not expressed in percents, i.e., as 0.0005. In this case, 100 * 0.0005 = 0.05 and no division by 100 is necessary. (This is not to mention that your example from post #1 had spending equal to 5%, or 0.05 and not 0.05%.)
If you enter spending in percents, then budget = gdpinput * spending / 100.
If you enter spending as an actual fraction (not in percents), then budget = gdpinput * spending.