#   windchill.py
#   tpm
#   A program that prints a nicely formatted table of windchill values.  


from math import *

def windchill(t, v):
    c = 35.74 + (0.6215 * t) - (35.75 * v ** .16) + (.4275 * t * v ** .16)
    return c

def main():
    print "MPH:",
    for k in range (-20, 70, 10):
        print "%3d" %k,
    print
    print "_" * 44
    for velocity in range (5, 55, 5):
        print "%3d" %velocity,
        for temp in range (-20, 70, 10):
            chill = windchill(temp, velocity)
            print "%3d" %round(chill),
        print

    main()

:o

Dani AI

Generated

Two quick diagnostics and a cleaner alternative.

The most likely reasons the script “doesn’t run correctly” are (1) the final main() call is indented inside the main function (so it recurses instead of starting the program) and (2) a mismatch between Python 2 print syntax used in the post and a Python 3 interpreter. was on the right track about the call spacing — that indentation will cause a RecursionError — and mixing tabs/spaces or using from math import * can also mask problems.

Practical fixes and improvements:

  • Move the script entry point out to top level or use the recommended guard if __name__ == "__main__": main() so the program starts only once.
  • Use modern formatting (format() / f-strings) or explicit int(round(...)) when printing integers to avoid type/formatting surprises.
  • Compute v_pow = v ** 0.16 once per velocity to avoid repeated work.
  • Keep computation and presentation separate (one function returns the numeric value, another prints the table) so unit tests or single-value checks are easy.

A compact, modern example (Python 3) showing those ideas:

def windchill_f(t, v):
    v16 = v ** 0.16
    return 35.74 + 0.6215 * t - 35.75 * v16 + 0.4275 * t * v16

def print_table():
    temps = list(range(-20, 70, 10))
    print("MPH " + "".join(f"{t:4d}" for t in temps))
    print("_" * 44)
    for s in range(5, 55, 5):
        row = [int(round(windchill_f(t, s))) for t in temps]
        print(f"{s:3d} " + "".join(f"{c:4d}" for c in row))

if __name__ == "__main__":
    print_table()

Common debugging checklist: read the traceback (it shows the exact line and error type), confirm interpreter version (python --version), verify indentation is consistent (use 4 spaces), and avoid wildcard imports. These changes will also make it easier to answer follow-ups or convert the script for different output formats.

Recommended Answers

All 4 Replies

Assuming the formula is right, looks basically fine to me. Just be sure to remove the spaces from the main() subroutine you call at the end, there. Good Job!

A handy tip:
Be sure to place [code][/code] tags around your code. It's especially important with Python, because the spaces actually are part of the code structure.

is there other to write this program?

I WROTE 2 PROGRAMS FOR WINDCHILL, AND IT STILL NOT RUNNING CORRECTLY. I TRIED EVERYTHING.


:mad: :evil: :cry: :o :sad: :(

I WROTE 2 PROGRAMS FOR WINDCHILL, AND IT STILL NOT RUNNING CORRECTLY. I TRIED EVERYTHING.


:mad: :evil: :cry: :o :sad: :(

Um...

I just said it worked fine on my machine. What is the problem? What errors is the interpreter throwing?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.