May-07-2017, 08:11 AM
:-), no, use
range(user+1)
, i.e. in your code the argument to range
is user
, not n
Table of Temperatures... Help
|
May-07-2017, 08:11 AM
:-), no, use
range(user+1) , i.e. in your code the argument to range is user , not n
Thanks for all the help.. lol one last favor.. Here are my teachers instructions, I think my program fits the bill but I would greatly appreciate a second opinion, This assignment is worth 5 percent of my grade. Here are the instructions..
Quote:Create a python program that displays a table of temperatures. One column of the table should show Celsius temperatures and the other column should show Fahrenheit temperatures. def fahrenheit(celcius): return (celcius * 9 / 5) + 32 def main(): user = int(input("Enter a Number: ")) print() print("Celcius \t Farenheit") for t in range (user + 1): print(t, "\t\t ", fahrenheit(t)) main()
May-07-2017, 08:27 AM
I saw your assignment before you edit your OP :-)
(May-07-2017, 08:18 AM)zepel Wrote: Create a main function that will be responsible for capturing user input and using a loop to display the table. that's why I insisted on including the user input in the main function, not only because it's the right thing to do. The only problem I see is that you need to capture also the minimum value for Celsius temperature. Quote:Prompt the user for lower and upper Celsius values to display in the table. At the moment you start always at 1. Also remember that in some of the previous iterations of your code you were using range(start, stop, increment)
May-07-2017, 08:33 AM
Also, not sure if you need to do this but usually one would check the user input, e.g. what will happen if user instead of number, input some letters.
Once you take both min. and max. Celsius (btw. note the spelling :)) values, what will happen if min (as entered by the user) is actually greater than max (again - the one entered by the user)? Do you need to take care of cases like these or simply hope for correct user input?
So I need to create a second input?
"Prompt the user for lower and upper Celsius values to display in the table.". This was the part that confused me, I wasn't sure exactly what the teacher was wanting me to do. So you think the teacher is meaning negative Celsius numbers as well?
May-07-2017, 08:37 AM
May-07-2017, 08:41 AM
Good?
def fahrenheit(celcius): return (celcius * 9 / 5) + 32 def main(): user = int(input("Enter a Number: ")) user1 = int(input("Enter a second number: ")) print() print("Celcius \t Farenheit") for t in range (user, user1+1): print(t, "\t\t ", fahrenheit(t)) main()
May-07-2017, 08:41 AM
(May-07-2017, 08:34 AM)zepel Wrote: So you think the teacher is meaning negative Celsius numbers as well? more or less any start and end (within the limits defined by physics, of course):-) -10 to 110 20 to 30, etc. btw, this add to my argument that you need to check the user input, especially the one for min. |
|