def windchill(V,T):
    wc = 35.74 + .6215*T-35.75*(V**.16)+.4275*(V**.16)
    we = round(wc,2)
    return we

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

    for V in range(0,55,5):
        print(V)
        for T in range(-20,70,10):
            wc = windchill(V,T)
            print(V, "{0:1.1f}".format(wc), end="")

main()

Its python 3, I feel like I've tried everything, i.e. round(), int(), {0:1.1f}, but none are working the way I expected. I'm a CSC noob though, so I'm looking for a little help

Ah ah! recurrent question. I once started a thread with same issue. The best solution I know is

def iround(x):
    return int(x + (0.5 if x > 0 else -0.5))

Edited 5 Years Ago by Gribouillis: n/a

just tried it, i keep getting:

Temperature

Speed

---- -20 70 10 0 10 20 30 40 50 60
0
0 23.30 29.50 35.70 42.00 48.20 54.40 60.60 66.80 73.05
5 -22.45 -16.25 -10.05 -3.75 2.55 8.75 14.95 21.15 27.310
10 -27.810 -21.510 -15.310 -9.110 -2.910 3.310 9.510 15.810 22.015
15 -31.215 -24.915 -18.715 -12.515 -6.315 -0.115 6.115 12.315 18.620
20 -33.720 -27.520 -21.320 -15.120 -8.920 -2.720 3.620 9.820 16.025
25 -35.825 -29.625 -23.425 -17.225 -10.925 -4.725 1.525 7.725 13.930
30 -37.630 -31.330 -25.130 -18.930 -12.730 -6.530 -0.330 6.030 12.235
35 -39.135 -32.935 -26.635 -20.435 -14.235 -8.035 -1.835 4.435 10.640
40 -40.440 -34.240 -28.040 -21.840 -15.640 -9.340 -3.140 3.140 9.345
45 -41.645 -35.445 -29.245 -23.045 -16.845 -10.645 -4.345 1.945 8.150
50 -42.750 -36.550 -30.350 -24.150 -17.950 -11.750 -5.550 0.850 7.0


if i could get them to round to the same number I think it would line up as well

just tried it, i keep getting:

Temperature

Speed

---- -20 70 10 0 10 20 30 40 50 60
0
0 23.30 29.50 35.70 42.00 48.20 54.40 60.60 66.80 73.05
5 -22.45 -16.25 -10.05 -3.75 2.55 8.75 14.95 21.15 27.310
10 -27.810 -21.510 -15.310 -9.110 -2.910 3.310 9.510 15.810 22.015
15 -31.215 -24.915 -18.715 -12.515 -6.315 -0.115 6.115 12.315 18.620
20 -33.720 -27.520 -21.320 -15.120 -8.920 -2.720 3.620 9.820 16.025
25 -35.825 -29.625 -23.425 -17.225 -10.925 -4.725 1.525 7.725 13.930
30 -37.630 -31.330 -25.130 -18.930 -12.730 -6.530 -0.330 6.030 12.235
35 -39.135 -32.935 -26.635 -20.435 -14.235 -8.035 -1.835 4.435 10.640
40 -40.440 -34.240 -28.040 -21.840 -15.640 -9.340 -3.140 3.140 9.345
45 -41.645 -35.445 -29.245 -23.045 -16.845 -10.645 -4.345 1.945 8.150
50 -42.750 -36.550 -30.350 -24.150 -17.950 -11.750 -5.550 0.850 7.0


if i could get them to round to the same number I think it would line up as well

You must also remove your {0:1.1f} formatting:

def iround(x):
    return int(x + (0.5 if x > 0 else -0.5))

def windchill(V,T):
    wc = 35.74 + .6215*T-35.75*(V**.16)+.4275*(V**.16)
    we = iround(wc) # <---- used iround
    return we

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

    for V in range(0,55,5):
        print(V)
        for T in range(-20,70,10):
            wc = windchill(V,T)
            print(V, wc, end="") # <---  removed formatting

main()

Edited 5 Years Ago by Gribouillis: n/a

I tried that exactly, but now its rounding like this:


Temperature

Speed

---- -20 70 10 0 10 20 30 40 50 60
0
0 230 300 360 420 480 540 610 670 735
5 -225 -165 -105 -45 25 95 155 215 2710
10 -2810 -2210 -1510 -910 -310 310 1010 1610 2215
15 -3115 -2515 -1915 -1315 -615 015 615 1215 1920
20 -3420 -2820 -2120 -1520 -920 -320 420 1020 1625
25 -3625 -3025 -2325 -1725 -1125 -525 125 825 1430
30 -3830 -3130 -2530 -1930 -1330 -630 030 630 1235
35 -3935 -3335 -2735 -2035 -1435 -835 -235 435 1140
40 -4040 -3440 -2840 -2240 -1640 -940 -340 340 945
45 -4245 -3545 -2945 -2345 -1745 -1145 -445 245 850
50 -4350 -3750 -3050 -2450 -1850 -1250 -550 150 7

What is your expected result ? Your function windchill() first computes a floating number named wc, then you convert it to a we and return. Suppose that wc is 34.8768678, what do you want to output ?

I would hopefully like to get it to 34. I just don't understand why python made the number jump to 10 times the number as seen in the last post. It won't just compute a 34- its always 34.876 or 340 for some reason

I don't even know if I need the we = round(wc) as seen in the first post, its just something I tried

I would hopefully like to get it to 34. I just don't understand why python made the number jump to 10 times the number as seen in the last post. It won't just compute a 34- its always 34.876 or 340 for some reason

If you want 34, you don't need iround(), which gives 35 (the nearest integer). The problem is the V in your print(). I added a "@" separator to show your error

from __future__ import print_function

def iround(x):
    return int(x + (0.5 if x > 0 else -0.5))

def windchill(V,T):
    wc = 35.74 + .6215*T-35.75*(V**.16)+.4275*(V**.16)
    we = int(wc) # <---- this if you want 34, iround if you prefer 35
    return we

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

    for V in range(0,55,5):
        print(V)
        for T in range(-20,70,10):
            wc = windchill(V,T)
            print(V, "@", wc, end=" ") # <-----See ?

main()

Also it would be more logical that windchill() returns a floating number and that you round the number only in the call to print(). For example you can print iround(wc).

Edited 5 Years Ago by Gribouillis: n/a

python is adding a 0 to each of my numbers for some reason, it is rounding like I want I believe, but when I run it, all the numbers get a 0 added to them- I don't know why

python is adding a 0 to each of my numbers for some reason, it is rounding like I want I believe, but when I run it, all the numbers get a 0 added to them- I don't know why

It is not adding a 0: it's printing wc and the next V, which is 0 in the first line (and 5, 10, 15, .. in subsequent lines). Did you run the code I just posted to understand its output ?

Edited 5 Years Ago by Gribouillis: n/a

I see the problem but I can't figure out how to fix it, I been at it forever

I see the problem but I can't figure out how to fix it, I been at it forever

Well, here is my solution. It's not perfect: the next step is to print the numbers in fixed width fields using format(), but I won't help you on this. See http://www.daniweb.com/software-development/python/code/232375

def iround(x):
    return int(x + (0.5 if x > 0 else -0.5))

def windchill(V,T):
    wc = 35.74 + .6215*T-35.75*(V**.16)+.4275*(V**.16)
    return wc # <------------- return a float here because it's a physical quantity

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

    for V in range(0,55,5):
        print(V, end="")
        for T in range(-20,70,10):
            wc = windchill(V,T)
            print(iround(wc), end=" ") # <-------------- V removed !
        print()

main()

Edited 5 Years Ago by Gribouillis: n/a

its an ugly table, but I've spent well over 18 hours on this... its good enough for me.

This question has already been answered. Start a new discussion instead.