Hello everyone
I am very close to being able to finish this one. I just have a formatting issue that my professor requires be done in a certain way.
He wants all of the data to be in three columns relatively neat looking. The point of this program is to accept two values (temperatures in this case) n and m. It will take every integer between n and m and calculate it from Fahrenheit (which is what you enter it in as) and calculate it to Celsius and Rankine. So, if n is 1 and m is 5 it will calculate 1, 2, 3, 4, and 5 into Celsius and Rankine.
Each of these must be stored in a separate list which I have done. I asked my professor how to do this and he told me to output all three lists on the same line (so the output lines up and looks good), and he told me to print all three lists on the same line. It works sometimes, but not always. If n is greater than 0, it throws an Index Error. If m is less than 0 it throws the same error. The bounds for this are no less then -30 and no more than 130 for n and m values. However, if you make n = -20 and m = 0, it works just fine and prints what it's supposed to. Also, if you make n too large (ex: n = 70 and m = 100), it will throw the same IndexError saying the list index is out of range.
Let me know if I explained that enough if not, I'll try to go into more detail
my code:
I am very close to being able to finish this one. I just have a formatting issue that my professor requires be done in a certain way.
He wants all of the data to be in three columns relatively neat looking. The point of this program is to accept two values (temperatures in this case) n and m. It will take every integer between n and m and calculate it from Fahrenheit (which is what you enter it in as) and calculate it to Celsius and Rankine. So, if n is 1 and m is 5 it will calculate 1, 2, 3, 4, and 5 into Celsius and Rankine.
Each of these must be stored in a separate list which I have done. I asked my professor how to do this and he told me to output all three lists on the same line (so the output lines up and looks good), and he told me to print all three lists on the same line. It works sometimes, but not always. If n is greater than 0, it throws an Index Error. If m is less than 0 it throws the same error. The bounds for this are no less then -30 and no more than 130 for n and m values. However, if you make n = -20 and m = 0, it works just fine and prints what it's supposed to. Also, if you make n too large (ex: n = 70 and m = 100), it will throw the same IndexError saying the list index is out of range.
Let me know if I explained that enough if not, I'll try to go into more detail
my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
listf = [] listc = [] listk = [] n = int ( input ( "Enter start value: " )) m = int ( input ( "Enter end value: " )) print ( "Fahr" , "\t" "Celsius" , "\t" "Rankine" ) # first for loop calculates celcius and adds it to listc for ftc in range (n,(m + 1 )): c1 = (( 5 / 9 ) * (ftc - 32 )) listc.append(c1) # this loop adds each base temp into listf for ftc in range (n, (m + 1 )): f1 = ftc listf.append(f1) # this loop calculates rankine and adds it to listk for ftc in range (n, (m + 1 )): k1 = ftc + 459.67 listk.append(k1) #the next for loop is going to print everything vertically for i in listf: print (i, "\t" , "{:,.2f}" . format (listc[i]), "\t" , listk[i]) |