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
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)
I think I've figured it out.
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.
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?
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.