C++buntu
January 5th, 2010, 04:13 AM
Hi everyone,
I'm puzzled, I'm new to programming but I work my way up with Python. I have a question for the guru's out there.
There's my code:
# Filename: convert_temp.py
def C2F(C):
""" C2F(C) convert a Celsius to a Fahrenheit temperature.
Input: C: Celsius degree.
Output: F: Fahrenheit degree.
Example: >>> C2F(0)
32.0
"""
if C < -273.15:
raise ValueError('C = %g is a non-physical value.' % C)
else:
value = (9./5)*C + 32
return value
Now, when I run this in IPython, I obtain the following:
In [1]: from convert_temp import *
In [2]: C2F(0)
Out[2]: 32.0
In [3]: C2F(-400)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (38, 0))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/home/steeve/Py4cs/problems/chapter 03/<ipython console> in <module>()
/home/steeve/Py4cs/problems/chapter 03/convert_temp.pyc in C2F(C)
16 """
17 if C < -273.15:
---> 18 raise ValueError('C = %g is a non-physical value.' % C)
19 else:
20 value = (9./5)*C + 32
ValueError: C = -400 is a non-physical value.
Any help for my error?
Thanks,
C++buntu
I'm puzzled, I'm new to programming but I work my way up with Python. I have a question for the guru's out there.
There's my code:
# Filename: convert_temp.py
def C2F(C):
""" C2F(C) convert a Celsius to a Fahrenheit temperature.
Input: C: Celsius degree.
Output: F: Fahrenheit degree.
Example: >>> C2F(0)
32.0
"""
if C < -273.15:
raise ValueError('C = %g is a non-physical value.' % C)
else:
value = (9./5)*C + 32
return value
Now, when I run this in IPython, I obtain the following:
In [1]: from convert_temp import *
In [2]: C2F(0)
Out[2]: 32.0
In [3]: C2F(-400)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (38, 0))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/home/steeve/Py4cs/problems/chapter 03/<ipython console> in <module>()
/home/steeve/Py4cs/problems/chapter 03/convert_temp.pyc in C2F(C)
16 """
17 if C < -273.15:
---> 18 raise ValueError('C = %g is a non-physical value.' % C)
19 else:
20 value = (9./5)*C + 32
ValueError: C = -400 is a non-physical value.
Any help for my error?
Thanks,
C++buntu