Python Forum
Table of Temperatures... Help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Table of Temperatures... Help
#11
:-), no, use range(user+1), i.e. in your code the argument to range is user, not n
Reply
#12
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.
Create a main function that will be responsible for capturing user input and using a loop to display the table. Prompt the user for lower and upper Celsius values to display in the table. Use a counter-controlled loop to count from the lower value to the higher value. Each iteration of the loop, convert the Celsius value to it's Fahrenheit equivalent using the appropriate conversion function from PR 09 (Fahrenheit Function). Display the results to the screen in a pleasing format.


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()
Reply
#13
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)
Reply
#14
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?
Reply
#15
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?
Reply
#16
(May-07-2017, 08:34 AM)zepel Wrote: So I need to create a second input?

what do you think? I already gave you HEAVY hints in completing this assignment
Reply
#17
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()
Reply
#18
(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.
Reply
#19
The guy teaching my class said not to worry about user errors yet, so I think my program is good to go. I just need to fix the spelling error lol.

Thanks for all the help buran!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020