I'm totall beginner, trying to learn python programming codes. So far, got series of python programming problems to solve. Here is one of them.; please I need help on how to write the program.

"Write a program that displays a table of the Celsius temperatures 0 through 20 and their Fahrenheit equivalents. The formula for converting a temperature from Celsius to Fahrenheit is F=9/5*c+32 where F is the Fahrenheit temperature and C is the Celsius temperature. Your program must use a loop to display the table."

As I said, the first step here would be to write a function that returns accpets the Celsius value and returns the Fahrenheit value. …

Mildly helpful hint for the loop ...

``````for c in range(0, 21):
print("Celsius = {}".format(c))

''' result ...
Celsius = 0
Celsius = 1
Celsius = 2
Celsius = 3
Celsius = 4
Celsius = 5
Celsius = 6
Celsius = 7
Celsius = 8
Celsius = 9
Celsius …``````

try this and let me know if it works for you.

``````start = 0
end = 21
increment = 1

def main():
print('The following table shows conversion of Celsius to Farenheit')
print( 'between 0 and 20 degrees Celsius.')
print('')
print('Celsius\t   Farenheit')
print('____________________')

#convert celsius input to …``````

## All 10 Replies

What, if anything, do you have already?

I would recommend starting with a simple function that takes a Celsius value and returns the Fahrenheit equivalent. If you don't know how to write a function, let us know and we'll explain it for you.

I do not know how to write the simple function., please explain me the detail code

I thought I could get the steps through guide that solves this problem. As a beginner, its really hard for me to solve this problem with the page you suggested.

You can start by writing pseudo-code to describe the different things that your program must do

``````# print a message saying that the following table
# displays temperatures in celsius and their
# conversion to farenheit.

Your-code-here

# set the celsius temperature C to zero

Your-code-here

# while the celsius temperature C is <= 20 degrees

Your-code-here

# compute the farenheit temperature F

Your-code-here

# print the 2 temperatures C and F

Your-code-here

# increase the temperature C by one degree

Your-code-here
``````

thanks so much. I'm going to look at this, hope it works. The python 3.3 I'm learning most times require int or float inputs.

As I said, the first step here would be to write a function that returns accpets the Celsius value and returns the Fahrenheit value. Before we can do that, though, we need to work out just how to convert a Celsius value to Fahrenheit. As it happens, this part was already given to you:

``````f = 9 / 5 * c + 32
``````

So, taking this one step at a time, let's see how this works. If you open up the Python interpreter, and enter

``````c = 0
``````

then enter the formula above, followed by

``````f
``````

you should get back the value `32.0`. OK, then! Now what you need to do is make the function, which would simply be

``````def celsius2fahr(c):
return 9 / 5 * c + 32
``````

basically, all we've done is give the formula above a name, `celsius2fahr()`. To test it, try entering

``````celsius2fahr(100)
``````

this should give you `212.0` as the result. you now have a way of repeatedly getting a Fahrenheit value from a Celsius value.

I've got to go now, but this should at least move you in the right direction.

Mildly helpful hint for the loop ...

``````for c in range(0, 21):
print("Celsius = {}".format(c))

''' result ...
Celsius = 0
Celsius = 1
Celsius = 2
Celsius = 3
Celsius = 4
Celsius = 5
Celsius = 6
Celsius = 7
Celsius = 8
Celsius = 9
Celsius = 10
Celsius = 11
Celsius = 12
Celsius = 13
Celsius = 14
Celsius = 15
Celsius = 16
Celsius = 17
Celsius = 18
Celsius = 19
Celsius = 20
'''
``````

try this and let me know if it works for you.

``````start = 0
end = 21
increment = 1

def main():
print('The following table shows conversion of Celsius to Farenheit')
print( 'between 0 and 20 degrees Celsius.')
print('')
print('Celsius\t   Farenheit')
print('____________________')

#convert celsius input to farenheit using loop
for Celsius in range (start, end, increment):
Farenheit = (9 / 5) * Celsius + 32
print(Celsius, '\t', format(Farenheit, '.1f'))

main()
``````
commented: Excellent ! +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.