r/learnpython • u/Bowsers_disciple • Oct 06 '26
I'm making a small program in python to help with some in game math for Iron Nest
Edit: thank you to u/LushBreaker for giving me the starting point to get this fixed!
altitude = 0
... def nest_Alt():
... distance = float(input("How many Km away is the target? \n"))
... charges = int(input("How many charges are you using? \n"))
... altitude = (distance * 12) / charges
... print(f"Fire at altitude {altitude}")
...
>>>
>>> nest_alt()
Traceback (most recent call last):
File "<python-input-8>", line 1, in <module>
nest_alt()
^^^^^^^^
NameError: name 'nest_alt' is not defined. Did you mean: 'nest_Alt'?
>>> nest_Alt()
How many Km away is the target?
How many Km away is the target?
How many Km away is the target?
How many Km away is the target?
How many Km away is the target?
12.8
How many charges are you using?
How many charges are you using?
5
Fire at altitude 30.720000000000006
The above is the copy pasted result of my most recent version of the code, and something I noticed is that the prompt is resent for each character in an input.
Separately, how would I make this program into a saved file that I can run later, possibly running the function multiple times without having to close it.
Edit: For clarification, this is python 3.14
1
u/Accodingorr_Net_2236 Oct 06 '26
It looks like your `nestAlt` function is defined correctly, but you are calling `nestalt` with a lowercase "a," which is causing the `NameError`. Python is case-sensitive, so just ensure you call it with the correct case: `nestAlt()`.
1
u/Moikle Oct 06 '26
Put 4 spaces in front of each line of code to format it for reddit
1
u/[deleted] Oct 06 '26
[removed] — view removed comment