Re: [Tutor] Issues converting a script to a functioin (or something) [SOLVED]

2016-05-01 Thread Olaoluwa Thomas
Gotcha.

*Warm regards,*

*Olaoluwa O. Thomas,*
*+2347068392705*

On Sun, May 1, 2016 at 7:14 PM, Alan Gauld via Tutor 
wrote:

> On 01/05/16 14:38, Olaoluwa Thomas wrote:
>
> > Thanks for your feedback. Please do not hesitate to provide more as I
> shall
> > email you personally in the future.
>
> Please don't do that.
> a) Bob is a busy man who volunteers his time here, but may
>have other things to do too.
> b) The list is here so that everyone can benefit from the
>discussions not only the people actively involved.
>
>
> > The problem was that running the code gave an error which I now do not
> > remember in detail as I have moved on after having fixed it.
>
> But the answer is nearly always in the detail. And as you get
> more advanced in coding the errors get harder to spot. That's
> why it is important to supply us (or any other forum) with
> as much detail as you can.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues converting a script to a functioin (or something) [SOLVED]

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 14:38, Olaoluwa Thomas wrote:

> Thanks for your feedback. Please do not hesitate to provide more as I shall
> email you personally in the future.

Please don't do that.
a) Bob is a busy man who volunteers his time here, but may
   have other things to do too.
b) The list is here so that everyone can benefit from the
   discussions not only the people actively involved.


> The problem was that running the code gave an error which I now do not
> remember in detail as I have moved on after having fixed it.

But the answer is nearly always in the detail. And as you get
more advanced in coding the errors get harder to spot. That's
why it is important to supply us (or any other forum) with
as much detail as you can.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues converting a script to a functioin (or something)

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 12:55, Olaoluwa Thomas wrote:

> It computes total pay based on two inputs, no. of hours and hourly rate.

While you do specify two inputs you immediately throw them away
and ask the user to provide the information. In general it is good
practice to separate calculation from input/output operations.
So in your case write the function to take the values provided by the
user and return(not print) the result.

Then when you call the function you pass in the values from the
user and print the function output. This makes the function more
likely to be reusable in other scenarios and easier to debug/test.

def computePay(hours, rate):
   # an exercise for the reader...

hours = float(raw_input ('How many hours do you work?\n'))
rate = float(raw_input ('What is your hourly rate?\n'))
print computPay(hours, rate)

> Something seems to be broken.

You must learn to provide more specific comments.
Define what is broken. Do you get an error message?
If so send it (all of it, not just a summary)
If no error message what output did you get?
What did you expect?

Otherwise we wind up just guessing at what is going on.
(And only a fool would run allegedly faulty code from
  an unknown source! :-)

> Here's the code:
> def computepay(hours, rate):
> hours = float(raw_input ('How many hours do you work?\n'))
> rate = float(raw_input ('What is your hourly rate?\n'))
> if hours > 40:
> gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
> elif hours >= 0 and hours <= 40:
> gross = hours * rate
> print "Your Gross pay is "+str(round(gross, 4))
> 
> computepay()

In this cae I'll guess it's the fact that you tell Python that
computePay is a function that takes two arguments (hours, rate)
but then call it with no arguments. But you should have got
an error message saying something very like that?
Here is what I get:

>>> def f(x,y): pass
...
>>> f()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: f() missing 2 required positional arguments: 'x' and 'y'
>>>

That's why including the error message helps  so much...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues converting a script to a functioin (or something)

2016-05-01 Thread Sreenathan Nair
On Sun, May 01, 2016 at 5:34 PM, Olaoluwa Thomas < thomasolaol...@gmail.com 
[thomasolaol...@gmail.com] > wrote:

The novice Python programmer is back.

I'm trying to incorporate a function and its call in the GrossPay.py script
that Alan solved for me.
It computes total pay based on two inputs, no. of hours and hourly rate.

There's a computation for overtime payments in the if statement.

Something seems to be broken.

Here's the code:
def computepay(hours, rate):
hours = float(raw_input ('How many hours do you work?\n'))
rate = float(raw_input ('What is your hourly rate?\n'))
if hours > 40:
gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
elif hours >= 0 and hours <= 40:
gross = hours * rate
print "Your Gross pay is "+str(round(gross, 4))

computepay()

What am I doing wrong?

*Warm regards,*

*Olaoluwa O. Thomas,*
*+2347068392705*
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor




Hi, The parameters hours and rate are required when calling the method 
computepay ex: computepay(8, 200), so basically computepay() by itself will 
throw an error  Also, as a suggestion if you're gonna get hours and 
rate via user input perhaps they can be removed from the method definition?

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues converting a script to a functioin (or something) [SOLVED]

2016-05-01 Thread isaac tetteh
You have two arguments in you function but when you call the function no 
argument is set in. Take the arguments out from the function if you want to use 
the the values from the user. 

Sent from my iPhone

> On May 1, 2016, at 8:41 AM, Olaoluwa Thomas  wrote:
> 
> Hi Bob,
> 
> Thanks for your feedback. Please do not hesitate to provide more as I shall
> email you personally in the future.
> 
> The script is made up of a function definition and its call prompting the
> user for input.
> 
> The script itself takes "number of hours worked" and "hourly rate" as
> inputs and gives gross pay as a product of the two.
> As I stated in my earlier email, there is also a portion for calculating
> gross pay with considerations for overtime (> 40 hours worked).
> 
> The problem was that running the code gave an error which I now do not
> remember in detail as I have moved on after having fixed it.
> 
> Here's the initial email below with Sreenathan's helpful input followed by
> my amendments to the code:
> (I thought my initial email was quite self-explanatory but what do I
> know... Please read through to the end)
> 
> On Sun, May 1, 2016 at 1:09 PM, Sreenathan Nair 
> wrote:
> 
>> On Sun, May 01, 2016 at 5:34 PM, Olaoluwa Thomas 
>> wrote:
>> 
>> The novice Python programmer is back.
>> 
>> I'm trying to incorporate a function and its call in the GrossPay.py
>> script
>> that Alan solved for me.
>> It computes total pay based on two inputs, no. of hours and hourly rate.
>> 
>> There's a computation for overtime payments in the if statement.
>> 
>> Something seems to be broken.
>> 
>> Here's the code:
>> def computepay(hours, rate):
>>hours = float(raw_input ('How many hours do you work?\n'))
>>rate = float(raw_input ('What is your hourly rate?\n'))
>>if hours > 40:
>>gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
>>elif hours >= 0 and hours <= 40:
>>gross = hours * rate
>>print "Your Gross pay is "+str(round(gross, 4))
>> 
>> computepay()
>> 
>> What am I doing wrong?
>> 
>> *Warm regards,*
>> 
>> *Olaoluwa O. Thomas,*
>> *+2347068392705*
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>> 
>> Hi,
>> The parameters hours and rate are required when calling the method
>> computepay ex: computepay(8, 200), so basically computepay() by itself will
>> throw an error  Also, as a suggestion if you're gonna get hours and
>> rate via user input perhaps they can be removed from the method definition?
>> 
>> ​Thanks, Sreenathan. These alterations solved it.
> 
> def computepay(hours, rate):
>if hours > 40:
>gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
>elif hours >= 0 and hours <= 40:
>gross = hours * rate
>print "Your Gross pay is "+str(round(gross, 4))
> computepay(hours = float(raw_input ('How many hours do you work?\n')), rate
> = float(raw_input ('What is your hourly rate?\n')))
> 
> *Warm regards,*
> 
> *Olaoluwa O. Thomas,*
> *+2347068392705*
> 
>> On Sun, May 1, 2016 at 2:13 PM, Bob Gailer  wrote:
>> 
>> 
>> On May 1, 2016 8:04 AM, "Olaoluwa Thomas" 
>> wrote:
>>> 
>>> The novice Python programmer is back.
>> Welcome back. We are here to help you when you are stuck. Telling us
>> something is broken is not adequate. Tell us-what you are expecting the
>> program to do and what results you're getting.
>>> 
>>> I'm trying to incorporate a function and its call in the GrossPay.py
>> script
>>> that Alan solved for me.
>>> It computes total pay based on two inputs, no. of hours and hourly rate.
>>> 
>>> There's a computation for overtime payments in the if statement.
>>> 
>>> Something seems to be broken.
>>> 
>>> Here's the code:
>>> def computepay(hours, rate):
>>>hours = float(raw_input ('How many hours do you work?\n'))
>>>rate = float(raw_input ('What is your hourly rate?\n'))
>>>if hours > 40:
>>>gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
>>>elif hours >= 0 and hours <= 40:
>>>gross = hours * rate
>>>print "Your Gross pay is "+str(round(gross, 4))
>>> 
>>> computepay()
>>> 
>>> What am I doing wrong?
>>> 
>>> *Warm regards,*
>>> 
>>> *Olaoluwa O. Thomas,*
>>> *+2347068392705*
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> To unsubscribe or change subscription options:
>>> https://mail.python.org/mailman/listinfo/tutor
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues converting a script to a functioin (or something) [SOLVED]

2016-05-01 Thread Olaoluwa Thomas
Hi Bob,

Thanks for your feedback. Please do not hesitate to provide more as I shall
email you personally in the future.

The script is made up of a function definition and its call prompting the
user for input.

The script itself takes "number of hours worked" and "hourly rate" as
inputs and gives gross pay as a product of the two.
As I stated in my earlier email, there is also a portion for calculating
gross pay with considerations for overtime (> 40 hours worked).

The problem was that running the code gave an error which I now do not
remember in detail as I have moved on after having fixed it.

Here's the initial email below with Sreenathan's helpful input followed by
my amendments to the code:
(I thought my initial email was quite self-explanatory but what do I
know... Please read through to the end)

On Sun, May 1, 2016 at 1:09 PM, Sreenathan Nair 
 wrote:

> On Sun, May 01, 2016 at 5:34 PM, Olaoluwa Thomas 
> wrote:
>
> The novice Python programmer is back.
>
> I'm trying to incorporate a function and its call in the GrossPay.py
> script
> that Alan solved for me.
> It computes total pay based on two inputs, no. of hours and hourly rate.
>
> There's a computation for overtime payments in the if statement.
>
> Something seems to be broken.
>
> Here's the code:
> def computepay(hours, rate):
> hours = float(raw_input ('How many hours do you work?\n'))
> rate = float(raw_input ('What is your hourly rate?\n'))
> if hours > 40:
> gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
> elif hours >= 0 and hours <= 40:
> gross = hours * rate
> print "Your Gross pay is "+str(round(gross, 4))
>
> computepay()
>
> What am I doing wrong?
>
> *Warm regards,*
>
> *Olaoluwa O. Thomas,*
> *+2347068392705*
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>  Hi,
> The parameters hours and rate are required when calling the method
> computepay ex: computepay(8, 200), so basically computepay() by itself will
> throw an error  Also, as a suggestion if you're gonna get hours and
> rate via user input perhaps they can be removed from the method definition?
>
> ​Thanks, Sreenathan. These alterations solved it.

def computepay(hours, rate):
if hours > 40:
gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
elif hours >= 0 and hours <= 40:
gross = hours * rate
print "Your Gross pay is "+str(round(gross, 4))
computepay(hours = float(raw_input ('How many hours do you work?\n')), rate
= float(raw_input ('What is your hourly rate?\n')))

*Warm regards,*

*Olaoluwa O. Thomas,*
*+2347068392705*

On Sun, May 1, 2016 at 2:13 PM, Bob Gailer  wrote:

>
> On May 1, 2016 8:04 AM, "Olaoluwa Thomas" 
> wrote:
> >
> > The novice Python programmer is back.
> Welcome back. We are here to help you when you are stuck. Telling us
> something is broken is not adequate. Tell us-what you are expecting the
> program to do and what results you're getting.
> >
> > I'm trying to incorporate a function and its call in the GrossPay.py
> script
> > that Alan solved for me.
> > It computes total pay based on two inputs, no. of hours and hourly rate.
> >
> > There's a computation for overtime payments in the if statement.
> >
> > Something seems to be broken.
> >
> > Here's the code:
> > def computepay(hours, rate):
> > hours = float(raw_input ('How many hours do you work?\n'))
> > rate = float(raw_input ('What is your hourly rate?\n'))
> > if hours > 40:
> > gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
> > elif hours >= 0 and hours <= 40:
> > gross = hours * rate
> > print "Your Gross pay is "+str(round(gross, 4))
> >
> > computepay()
> >
> > What am I doing wrong?
> >
> > *Warm regards,*
> >
> > *Olaoluwa O. Thomas,*
> > *+2347068392705*
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issues converting a script to a functioin (or something)

2016-05-01 Thread Bob Gailer
On May 1, 2016 8:04 AM, "Olaoluwa Thomas"  wrote:
>
> The novice Python programmer is back.
Welcome back. We are here to help you when you are stuck. Telling us
something is broken is not adequate. Tell us-what you are expecting the
program to do and what results you're getting.
>
> I'm trying to incorporate a function and its call in the GrossPay.py
script
> that Alan solved for me.
> It computes total pay based on two inputs, no. of hours and hourly rate.
>
> There's a computation for overtime payments in the if statement.
>
> Something seems to be broken.
>
> Here's the code:
> def computepay(hours, rate):
> hours = float(raw_input ('How many hours do you work?\n'))
> rate = float(raw_input ('What is your hourly rate?\n'))
> if hours > 40:
> gross = ((hours - 40) * (rate * 1.5)) + (40 * rate)
> elif hours >= 0 and hours <= 40:
> gross = hours * rate
> print "Your Gross pay is "+str(round(gross, 4))
>
> computepay()
>
> What am I doing wrong?
>
> *Warm regards,*
>
> *Olaoluwa O. Thomas,*
> *+2347068392705*
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor