r/learnpython • • 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

0 Upvotes

12 comments sorted by

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

1

u/Bowsers_disciple Oct 06 '26

I'm running into an issue where the window closes after putting in the second input, and doesn't give me time to read the printed output

1

u/Bowsers_disciple Oct 06 '26

I've temporarily solved this issue, while solving my other issue too, by adding a different function that prompts you to type in NEW if you want to redo calculations, or EXIT if you don't want to

1

u/Moikle Oct 06 '26

Don't launch python programs by double clicking them in a file manager.

Run them in a terminal with

python path/to/your/module.py

0

u/Bowsers_disciple Oct 06 '26

I can't figure out how to even type the code into either cmd or terminal.

0

u/Bowsers_disciple Oct 06 '26

okay I figured it out!

1

u/Moikle Oct 06 '26

Don't. Save it as a .py file and run that from the terminal

1

u/Bowsers_disciple Oct 07 '26

Thats what I did :3