butterflyTee 0 Light Poster

I WRITTEN THIS PROGRAMM IN 2 WAYS(RE-WROTE IT OVER AND OVER), AND ITS STILL NOT RUNNING CORRECTLY. IS THERE OTHER WAYS THAT IS PROGRAM CAN BE WRITTEN. I AM SO FRUSTRATED, PLEASE HELP ME. THANK YOU.

1st way:

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


from math import *

def windchill(t, v):
c = 35.74 + .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()

2nd way:

def windchill( vel, temp):
wc = 35.74 + .6215*temp - 35.75*(vel**.16) + .4275*temp*(vel**.16)
return wc

def main():
print (" __ __ __ Temperature \n")
print ("Speed \n")
print (" 1 -20 70 10 0 10 20 30 40 50 60 ")


for x in range(5, 55, 5):
print x
for y in range (-20, 70, 10):
chill = windchill(x,y)
print str(int(chill)) + " ",


print main()


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

Dani AI

Generated

Short diagnosis for : the two posted versions mix Python 2‑style and Python 3‑style constructs, and that almost always causes the “not running correctly” behaviour. Common symptoms are syntax errors for print statements, unexpected output when using trailing commas to suppress newlines (different semantics in 2 vs 3), and printing the result of main() which will show None if main does not return a value. Indentation problems inside the function (so return is not actually inside the function) will also stop the function from working.

Practical checklist to fix this table program:

  • Decide on an interpreter and run the script explicitly (check with python --version or run python3 script.py).
  • Make all prints consistent: use the Python 3 print() form, or add from __future__ import print_function if staying on Python 2 while porting.
  • Replace trailing‑comma print idioms with the end= parameter (for Python 3) so rows and separators behave predictably.
  • Verify the return line is indented inside the function and that the function is called with the intended argument order.
  • Avoid print(main()) unless main returns a value; call main() directly to run it.
  • For alignment, build each output row with a single formatting method (format strings or f‑strings) so numbers line up cleanly.

References: for Python printing and formatting guidance see Porting to Python 3 — the print function and Format string syntax. For the wind‑chill formula and expected values see the wind chill reference: Wind chill — Wikipedia.

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.