Write a Python program to show the temperatures starting at zero degrees Celsius, up to 100 degrees Celsius, in steps of 2 degrees, with the corresponding Fahreneit temperature shown in the next column. Temperatures should be shown as floating point numbers to two decimal places. Use a for loop for displaying each line of the table and the following formula for the temperature conversion:

Example Program run:
C F
0.00 32.00
2.00 35.60
4.00 39.20
6.00 42.80
100.00 212.00
_____________________________________________________
I have written the program and it works, but the problem i have is, my professor only wants the even number and its corresponding farenheit values to be shows, how do i do that?

This is the code I have typed in for this assignment and it works, just need to know to display the range of even numbers and its corresponding Fahrenheit values only, my code:

while 1:  
    print ("C" + '\t' +"F")
    celsius = 0
    for celsius in range(0, 101):
        fahrenheit = 1.8 * celsius + 32 
        print ('%0.2f %0.2f' % (celsius,fahrenheit))
    answer = input("\nWould you like to run this program again? y/n\n")
    if answer == 'N' or answer == 'n':
        break
print ()
print ()
print ("Thank you for using this program.")
print ("Goodbye...")

Thanks in advance.

Tony

Moderator's note:
Please use code tags with your Python code to preserve the indentations. Otherwise the code is very difficult to read and not too many folks will help.

[code=python]
your Python code here

[/code]

Use a remainder modulator:

while 1:
print ("C" + '\t' +"F")
celsius = 0
for celsius in range(0, 101):
fahrenheit = 1.8 * celsius + 32
if celsius % 2 == 0:
print ('%0.2f %0.2f' % (celsius,fahrenheit))
else:
pass
answer = input("\nWould you like to run this program again? y/n\n")
if answer == 'N' or answer == 'n':
break
print ()
print ()
print ("Thank you for using this program.")
print ("Goodbye...")

This might need a little cleaning up, but should eliminate your odd numbers.

I tried to include indentation in this reply, but I now see that everything was left aligned. You should already understand tabs and indentation, but the if and else statements should be single tabbed and their respective executions should be double tabbed.

Use a remainder modulator:

while 1:
print ("C" + '\t' +"F")
celsius = 0
for celsius in range(0, 101):
fahrenheit = 1.8 * celsius + 32
if celsius % 2 == 0:
print ('%0.2f %0.2f' % (celsius,fahrenheit))
else:
pass
answer = input("\nWould you like to run this program again? y/n\n")
if answer == 'N' or answer == 'n':
break
print ()
print ()
print ("Thank you for using this program.")
print ("Goodbye...")

This might need a little cleaning up, but should eliminate your odd numbers.

Thank you so much for ur help, i managed to figure it out and it works like a flash, thanks so much....

Tony

To the both of you:

In order to preserve indentation use code tags while posting code in this forum like so:
[code=python] # Code goes inside here

[/code]

Just a note to remind you that range(start, stop, step) has a step option, so you could have used ...

for celsius in range(0, 101, 2):
    fahrenheit = 1.8 * celsius + 32 
    print ('%0.2f %0.2f' % (celsius,fahrenheit))

All in all, nice clean coding style. Hope you enjoy your Python experience.

Comments
haha brilliantly clean, simple solution
This question has already been answered. Start a new discussion instead.