Python tempature conversion

For the discussion of Perl, Python, Ruby, and PHP and other interpreted languages.

Python tempature conversion

Post by Reason7194 on Thu Jul 21, 2011 5:06 pm
([msg=59953]see Python tempature conversion[/msg])

Hello everyone, I am practicing Python by making a small program that converts Farenheight to Celsius and vice versa. This is what I have so far: http://slexy.org/view/s20JTLkRwQ My output however was not what I was expecting which is, with choosing the number 55 and the Celsius option, "<function Celsius at 0x00BF6FA8>". My questions are, why does " "<function Celsius at" print out when i only expected the hex number to print? Later on I want to change the hex number to a Decimal number and I think I can do that with ord(), but I am still getting a type error saying that ord() expected a string length of 1. Could anyone point me in the direction to finding my mistakes?
I study Gotafu.
Reason7194
Poster
Poster
 
Posts: 215
Joined: Fri Jan 07, 2011 5:01 pm
Blog: View Blog (0)


Re: Python tempature conversion

Post by Gatito on Thu Jul 21, 2011 5:48 pm
([msg=59954]see Re: Python tempature conversion[/msg])

I messed up with it a bit.
http://slexy.org/view/s2PaPr8WAF
User avatar
Gatito
Poster
Poster
 
Posts: 113
Joined: Tue Mar 08, 2011 12:55 pm
Blog: View Blog (0)


Re: Python tempature conversion

Post by Reason7194 on Thu Jul 21, 2011 6:13 pm
([msg=59955]see Re: Python tempature conversion[/msg])

and this worked for you?
I study Gotafu.
Reason7194
Poster
Poster
 
Posts: 215
Joined: Fri Jan 07, 2011 5:01 pm
Blog: View Blog (0)


Re: Python tempature conversion

Post by Gatito on Thu Jul 21, 2011 6:32 pm
([msg=59956]see Re: Python tempature conversion[/msg])

Yep!

First edited the Celsius() to Celsius(user), same with Fahreneit. After that the program displayed a number as a result, yet the math was wrong (dunno why, the syntax looked right). After I edited the 9/5 to 1.8 the math worked.

Did my version displayed any error and if yes what.
User avatar
Gatito
Poster
Poster
 
Posts: 113
Joined: Tue Mar 08, 2011 12:55 pm
Blog: View Blog (0)


Re: Python tempature conversion

Post by Reason7194 on Thu Jul 21, 2011 6:41 pm
([msg=59957]see Re: Python tempature conversion[/msg])

Well there are no errors, but there is no output haha. The program stops after it asks for celsius or farenheight.
I study Gotafu.
Reason7194
Poster
Poster
 
Posts: 215
Joined: Fri Jan 07, 2011 5:01 pm
Blog: View Blog (0)


Re: Python tempature conversion

Post by Vulpine on Thu Jul 21, 2011 6:43 pm
([msg=59958]see Re: Python tempature conversion[/msg])

That's because Python 2.x is a little different from the 3.x that you're using.

Try this.
http://slexy.org/view/s2xQLa6y7C

Edit: Whoops. Line 14 should be an elif.
User avatar
Vulpine
Poster
Poster
 
Posts: 381
Joined: Fri Mar 26, 2010 11:14 pm
Blog: View Blog (0)


Re: Python tempature conversion

Post by Gatito on Thu Jul 21, 2011 6:54 pm
([msg=59960]see Re: Python tempature conversion[/msg])

I for myself used 2.7 on this and strange enough Vulpine's version doesn't produce any output on my side. Wondering...

Edit: It does work when I change if '1' == pick to if 1 == pick
Last edited by Gatito on Thu Jul 21, 2011 6:59 pm, edited 1 time in total.
User avatar
Gatito
Poster
Poster
 
Posts: 113
Joined: Tue Mar 08, 2011 12:55 pm
Blog: View Blog (0)


Re: Python tempature conversion

Post by Reason7194 on Thu Jul 21, 2011 6:54 pm
([msg=59961]see Re: Python tempature conversion[/msg])

Actually all that was needed was changing the 'if' statments '==' to 'in'.
Code: Select all
if '1' in pick:


So now that it works, why did my original code now work? Like why did it produce a hex number and a unexpected output. Just so that I know for later projects, Gaito and Vulpine pretty much just gave me the answer which is not necessarily what I needed.
I study Gotafu.
Reason7194
Poster
Poster
 
Posts: 215
Joined: Fri Jan 07, 2011 5:01 pm
Blog: View Blog (0)


Re: Python tempature conversion

Post by Vulpine on Thu Jul 21, 2011 6:58 pm
([msg=59962]see Re: Python tempature conversion[/msg])

Gatito wrote:I for myself used 2.7 on this and strange enough Vulpine's version doesn't produce any output on my side. Wondering...


2.7 is ftw.

The initial problem was that Reason's script was trying to use strings in a math formula. Does not compute. He was also forgetting to pass his user variable to the methods.
User avatar
Vulpine
Poster
Poster
 
Posts: 381
Joined: Fri Mar 26, 2010 11:14 pm
Blog: View Blog (0)



Return to Interpreted Languages

Who is online

Users browsing this forum: No registered users and 0 guests