Re: Help with python functions?

2014-02-10 Thread tn156
On Monday, September 23, 2013 6:48:20 PM UTC-4, Terry Reedy wrote: On 9/23/2013 6:32 PM, kjaku...@gmail.com wrote: On Monday, September 23, 2013 9:56:45 AM UTC-4, Steven D'Aprano wrote: On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote: Now you're done! On to the next function...

Re: Help with python functions?

2014-02-10 Thread tn156
On Monday, September 23, 2013 6:48:20 PM UTC-4, Terry Reedy wrote: On 9/23/2013 6:32 PM, kjaku...@gmail.com wrote: On Monday, September 23, 2013 9:56:45 AM UTC-4, Steven D'Aprano wrote: On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote: Now you're done! On to the next function...

Re: Help with python functions?

2013-10-01 Thread kjakupak
I ended up with these. I know they're only like half right... I was wondering if any of you had to do this, what would you end up with? # Question 1.a def temp(T, from_unit, to_unit): if from_unit == 'C' or from_unit == 'c': return 32 + (9/5)*T elif from_unit == 'K' or from_unit

Re: Help with python functions?

2013-10-01 Thread random832
On Tue, Oct 1, 2013, at 13:53, kjaku...@gmail.com wrote: I ended up with these. I know they're only like half right... I was wondering if any of you had to do this, what would you end up with? # Question 1.a def temp(T, from_unit, to_unit): Assuming this is temperature conversion. You

Re: Help with python functions?

2013-10-01 Thread Denis McMahon
On Tue, 01 Oct 2013 10:53:26 -0700, kjakupak wrote: I ended up with these. I know they're only like half right... I was wondering if any of you had to do this, what would you end up with? # Question 1.a def temp(T, from_unit, to_unit): I suspect that this doesn't work properly for all

Re: Help with python functions?

2013-09-24 Thread Denis McMahon
On Mon, 23 Sep 2013 19:40:47 -0700, kjakupak wrote: Not sure if we've gotten that far in class, considering I don't know how to go about doing that. Which bit aren't you sure about? (a) adding a same unit conversion to the units conversion program? (Actually, this bit isn't needed after all,

Re: Help with python functions?

2013-09-24 Thread Denis McMahon
On Tue, 24 Sep 2013 03:15:23 +, Steven D'Aprano wrote: You don't have to use Kelvin. You could use any temperature scale, so long as it is the same for both temperatures. Given that he already has a handy conversion function to call, he should be able to convert t2 into the units of t1 if

Re: Help with python functions?

2013-09-24 Thread giacomo boffi
kjaku...@gmail.com writes: def temp(T, from_unit, to_unit): conversion_table = {('c', 'k'):lambda x: x + 273.15, ('c', 'f'):lambda x: (x * (9.0/5)) + 32, ('k', 'c'):lambda x: x - 273.15, ('k', 'f'):lambda x: (x *

Re: Help with python functions?

2013-09-24 Thread MRAB
On 24/09/2013 17:53, giacomo boffi wrote: kjaku...@gmail.com writes: def temp(T, from_unit, to_unit): conversion_table = {('c', 'k'):lambda x: x + 273.15, ('c', 'f'):lambda x: (x * (9.0/5)) + 32, ('k', 'c'):lambda x: x - 273.15,

Re: Help with python functions?

2013-09-24 Thread Denis McMahon
On Tue, 24 Sep 2013 14:51:31 +, Denis McMahon wrote: Question, given the original temp function as previously described by yourself, what does the following function f which takes the same params as comp do: def f( t1, u1, t2, u2 ): if u1 == u2: return t2 else:

Help with python functions?

2013-09-23 Thread kjakupak
1.a. Write a function temp(T, from_unit, to_unit) where from_unit and to_unit are temperature units, either 'F' (or 'f') for fahrenheit, or 'C' (or 'c') for celsius, or 'K' (or 'k') for kelvin; and T is a temperature number for the unit from_unit. The function should return the temperature

Re: Help with python functions?

2013-09-23 Thread Roy Smith
In article e484b709-1287-4e6a-bc43-05f02a608...@googlegroups.com, kjaku...@gmail.com wrote: 1.a. Write a function temp(T, from_unit, to_unit) where from_unit and to_unit are temperature units, either 'F' (or 'f') for fahrenheit, or 'C' (or 'c') for celsius, or 'K' (or 'k') for kelvin; and T

Re: Help with python functions?

2013-09-23 Thread Steven D'Aprano
On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote: Can anyone help me with any of these please? Much appreciated. I honestly don't even know how to start them Start by writing a function that does nothing: def nothing(): pass Now change it so that it takes three arguments: T, a

Re: Help with python functions?

2013-09-23 Thread kjakupak
On Monday, September 23, 2013 9:56:45 AM UTC-4, Steven D'Aprano wrote: On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote: Now you're done! On to the next function... -- Steven def temp(T, from_unit, to_unit): conversion_table = {('c', 'k'):lambda x: x + 273.15,

Re: Help with python functions?

2013-09-23 Thread Terry Reedy
On 9/23/2013 6:32 PM, kjaku...@gmail.com wrote: On Monday, September 23, 2013 9:56:45 AM UTC-4, Steven D'Aprano wrote: On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote: Now you're done! On to the next function... -- Steven def temp(T, from_unit, to_unit): conversion_table = {('c',

Re: Help with python functions?

2013-09-23 Thread kjakupak
On Monday, September 23, 2013 9:56:45 AM UTC-4, Steven D'Aprano wrote: On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote: Now you're done! On to the next function... -- Steven def temp(T, from_unit, to_unit): conversion_table = {('c', 'k'):lambda x: x + 273.15,

Re: Help with python functions?

2013-09-23 Thread Dave Angel
On 23/9/2013 18:55, kjaku...@gmail.com wrote: On Monday, September 23, 2013 9:56:45 AM UTC-4, Steven D'Aprano wrote: On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote: Now you're done! On to the next function... -- Steven def temp(T, from_unit, to_unit):

Re: Help with python functions?

2013-09-23 Thread kjakupak
On Monday, September 23, 2013 8:07:44 PM UTC-4, Dave Angel wrote: I didn't see any spec that said Python 3.x. in version 2.x, this would be incorrect. -- DaveA It's for Python 3.2 -- https://mail.python.org/mailman/listinfo/python-list

Re: Help with python functions?

2013-09-23 Thread Denis McMahon
On Mon, 23 Sep 2013 15:55:53 -0700, kjakupak wrote: As for the next one, so far I've gotten: def comp(T1, u1, T2, u2): if u1 u2: return -1 elif u2 u1: return 1 else: return 0 If the first function you wrote allows you to convert temps in different

Re: Help with python functions?

2013-09-23 Thread kjakupak
On Monday, September 23, 2013 10:12:05 PM UTC-4, Denis McMahon wrote: If the first function you wrote allows you to convert temps in different scales to a common scale, then in the second function, you can call the first function to convert both temps to a common scale, and compare

Re: Help with python functions?

2013-09-23 Thread Steven D'Aprano
On Mon, 23 Sep 2013 15:32:37 -0700, kjakupak wrote: On Monday, September 23, 2013 9:56:45 AM UTC-4, Steven D'Aprano wrote: On Mon, 23 Sep 2013 05:57:34 -0700, kjakupak wrote: Now you're done! On to the next function... -- Steven def temp(T, from_unit, to_unit):

Re: Help with python functions?

2013-09-23 Thread Steven D'Aprano
On Mon, 23 Sep 2013 15:55:53 -0700, kjakupak wrote: As for the next one, so far I've gotten: def comp(T1, u1, T2, u2): if u1 u2: return -1 elif u2 u1: return 1 else: return 0 That is only comparing the units, not the temperatures. Since the units

Re: Help with python functions?

2013-09-23 Thread Steven D'Aprano
On Mon, 23 Sep 2013 15:32:37 -0700, kjakupak wrote: def temp(T, from_unit, to_unit): conversion_table = {('c', 'k'):lambda x: x + 273.15, ('c', 'f'):lambda x: (x * (9.0/5)) + 32, ('k', 'c'):lambda x: x - 273.15,

Re: Help with python functions?

2013-09-23 Thread Dave Angel
On 23/9/2013 21:23, kjaku...@gmail.com wrote: On Monday, September 23, 2013 8:07:44 PM UTC-4, Dave Angel wrote: I didn't see any spec that said Python 3.x. in version 2.x, this would be incorrect. -- DaveA It's for Python 3.2 Then I'd have a comment saying so, right at the