Welcome to Gaia! ::

Reply
A question about floating point #'s~~PYTHON PROGRAMMING

Quick Reply

Enter both words below, separated by a space:

Can't read the text? Click here

Submit

Linux rules!!!Its the best!!
Yes it does !(starts customizing OS to your needz...)
100%
 100%  [ 2 ]
Sorry, dont like it [Hugs Microsoft Windows or MacOS]
0%
 0%  [ 0 ]
Total Votes : 2


EdThaSlayer

PostPosted: Thu Jun 01, 2006 12:39 am


iam kinda of a newb to python programming language...still doing tutorials...

but how do you convert a number to a floating point #?

all i know is how to either convert something to a integer or string

here is an example


#!/usr/bin/python
def fconvert():
fcconvert=True
while fcconvert:
temp=input("Fahrenheit temperature:")
if temp=="quit":#Will exit to main combo program if quit is entered
fcconvert=False
else:
temp=int(temp)#CONVERTS TO INTEGER!
print "That would be",((temp-32.0)*5.0)/9.0,"Celcius"

but how do i make it so that when you input something into the input you can even enter in fractions such as 1.34, because when i put in whole numbers it works but when i try puting in fractions this happens


>>>
Fahrenheit temperature:78
That would be 25.5555555556 Celcius
Fahrenheit temperature:6
That would be -14.4444444444 Celcius
Fahrenheit temperature:44
That would be 6.66666666667 Celcius
Fahrenheit temperature:2312
That would be 1266.66666667 Celcius
Fahrenheit temperature:5.2

Traceback (most recent call last):
File "/home/edwin/ProgrammingRELATED/PYTHONrelated/Edwinsprograms/ComplexProgramEVA'/FahrenheitToCelcius.py", line 29, in -toplevel-
fconvert()
File "/home/edwin/ProgrammingRELATED/PYTHONrelated/Edwinsprograms/ComplexProgramEVA'/FahrenheitToCelcius.py", line 26, in fconvert
temp=int(temp)#CONVERTS TO INTEGER!
ValueError: invalid literal for int(): 5.2


A error pops up when i enter in a # that isnt whole...[i entered 5.2 in this]
-------------------------------------------------------------------------------------------------------

Is there a option to change the input to a floating point number?
Or isnt it possible...

Thanks to anyone who answers!
PostPosted: Fri Jun 02, 2006 3:20 pm


i kinda looked at the tutorials...they said all you have to do is add float to the ent


i think i found the answer by myself faster people and for all you guys that dont know!

just add float instead of int or str if you want to convert it to a fraction...

EdThaSlayer


EdThaSlayer

PostPosted: Sat Jun 03, 2006 12:26 pm


We really need more people participating in this forum...
Reply


 
Manage Your Items
Other Stuff
Get GCash
Offers
Get Items
More Items
Where Everyone Hangs Out
Other Community Areas
Virtual Spaces
Fun Stuff
Gaia's Games
Mini-Games
Play with GCash
Play with Platinum