# Newbee Question

Discussion in 'Python' started by HD1956, Aug 20, 2007.

1. ### HD1956Guest

This is probably a simple code. I am a truck driver who gets paid by
stops and cases. I am trying to figure out how to code my stop pay. I
get 40 cents per stop up to 22 stops, and \$1.40 per stops after that.

HD1956, Aug 20, 2007

2. ### Guest

On Aug 20, 9:23 am, "HD1956" <> wrote:
> This is probably a simple code. I am a truck driver who gets paid by
> stops and cases. I am trying to figure out how to code my stop pay. I
> get 40 cents per stop up to 22 stops, and \$1.40 per stops after that.

def calc(num):
if num < 23:
return 0.4 * num
else:
overtime = num - 22
x = 0.4 * 22
x += overtime * 1.4
return x

# Use your own brain next time

Mike

, Aug 20, 2007

3. ### Shawn MilochikGuest

On 8/20/07, <> wrote:
> On Aug 20, 9:23 am, "HD1956" <> wrote:
> > This is probably a simple code. I am a truck driver who gets paid by
> > stops and cases. I am trying to figure out how to code my stop pay. I
> > get 40 cents per stop up to 22 stops, and \$1.40 per stops after that.

>
> def calc(num):
> if num < 23:
> return 0.4 * num
> else:
> overtime = num - 22
> x = 0.4 * 22
> x += overtime * 1.4
> return x
>
> # Use your own brain next time
>
> Mike
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Mike,

I wonder if we were both just duped into helping someone with their homework...

Shawn

Shawn Milochik, Aug 20, 2007
4. ### Diez B. RoggischGuest

HD1956 schrieb:
> This is probably a simple code. I am a truck driver who gets paid by
> stops and cases. I am trying to figure out how to code my stop pay. I
> get 40 cents per stop up to 22 stops, and \$1.40 per stops after that.
>

Sounds a bit like homework. Which usually isn't simply delivered here.

Can you show us some code you worked on, then we might suggest enhancements.

Diez

Diez B. Roggisch, Aug 20, 2007
5. ### Guest

On Aug 20, 9:58 am, "Shawn Milochik" <> wrote:
> On 8/20/07, <> wrote:
>
>
>
> > On Aug 20, 9:23 am, "HD1956" <> wrote:
> > > This is probably a simple code. I am a truck driver who gets paid by
> > > stops and cases. I am trying to figure out how to code my stop pay. I
> > > get 40 cents per stop up to 22 stops, and \$1.40 per stops after that.

>
> > def calc(num):
> > if num < 23:
> > return 0.4 * num
> > else:
> > overtime = num - 22
> > x = 0.4 * 22
> > x += overtime * 1.4
> > return x

>
> > # Use your own brain next time

>
> > Mike

>
>
> Mike,
>
> I wonder if we were both just duped into helping someone with their homework...
>
> Shawn

I like to write code, so it's not a big deal when it's something so
simple. Still, that is beyond dumb! Nice code, by the way.

Mike

, Aug 20, 2007
6. ### Shawn MilochikGuest

> I like to write code, so it's not a big deal when it's something so
> simple. Still, that is beyond dumb! Nice code, by the way.
>
> Mike

Yeah, it was fun to write anyway. Thanks for the compliment on the
code. I still consider myself a Python newbie, so it's good to know
I'm not trying to write it like Perl or VBScript anymore. ^_^

Shawn

Shawn Milochik, Aug 20, 2007
7. ### Wildemar WildenburgerGuest

Diez B. Roggisch wrote:
> Sounds a bit like homework. Which usually isn't simply delivered here.
>
>

Wrong! Usually that happens pretty quickly here (as proven again in this
case). Not that it should, but only the seniors seem to detect lazy
learners.

/W

Wildemar Wildenburger, Aug 20, 2007
8. ### Paul McGuireGuest

On Aug 20, 9:23 am, "HD1956" <> wrote:
> This is probably a simple code. I am a truck driver who gets paid by
> stops and cases. I am trying to figure out how to code my stop pay. I
> get 40 cents per stop up to 22 stops, and \$1.40 per stops after that.

You'll get top marks for turning in the shortest program!

norm = 0.4
ot = 1.4-norm
otStart = 22
calcPay = lambda stops : norm*stops+ot*max(stops-otStart,0)

-- Paul

Paul McGuire, Aug 20, 2007
9. ### Neil CeruttiGuest

On 2007-08-20, HD1956 <> wrote:
> This is probably a simple code. I am a truck driver who gets
> paid by stops and cases. I am trying to figure out how to code
> my stop pay. I get 40 cents per stop up to 22 stops, and \$1.40
> per stops after that.

I wish *I* could make a deal like that. I stop working all the
time!

--
Neil Cerutti
Customers who consider our waitresses uncivil ought to see the manager --sign
at New York restaurant

Neil Cerutti, Aug 20, 2007
10. ### Guest

On Aug 20, 11:06 am, wrote:
> On Aug 20, 9:58 am, "Shawn Milochik" <> wrote:
>
>
>
>
>
> > On 8/20/07, <> wrote:

>
> > > On Aug 20, 9:23 am, "HD1956" <> wrote:
> > > > This is probably a simple code. I am a truck driver who gets paid by
> > > > stops and cases. I am trying to figure out how to code my stop pay. I
> > > > get 40 cents per stop up to 22 stops, and \$1.40 per stops after that.

>
> > > def calc(num):
> > > if num < 23:
> > > return 0.4 * num
> > > else:
> > > overtime = num - 22
> > > x = 0.4 * 22
> > > x += overtime * 1.4
> > > return x

>
> > > # Use your own brain next time

>
> > > Mike

>
> > > --
> > >http://mail.python.org/mailman/listinfo/python-list

>
> > Mike,

>
> > I wonder if we were both just duped into helping someone with their homework...

>
> > Shawn

>
> I like to write code, so it's not a big deal when it's something so
> simple. Still, that is beyond dumb! Nice code, by the way.
>
> Mike- Hide quoted text -
>
> - Show quoted text -

Thanks for the help. By the way I am trying to learn the python after
work and on weekends. If it was a dumb question, to this group, I will
not bother you all again.
Without help it will take me longer to learn. Thanks

, Aug 20, 2007
11. ### James StroudGuest

wrote:
> On Aug 20, 11:06 am, wrote:
>
>>On Aug 20, 9:58 am, "Shawn Milochik" <> wrote:
>>
>>
>>
>>
>>
>>
>>>On 8/20/07, <> wrote:

>>
>>>>On Aug 20, 9:23 am, "HD1956" <> wrote:
>>>>
>>>>>This is probably a simple code. I am a truck driver who gets paid by
>>>>>stops and cases. I am trying to figure out how to code my stop pay. I
>>>>>get 40 cents per stop up to 22 stops, and \$1.40 per stops after that.

>>
>>>>def calc(num):
>>>> if num < 23:
>>>> return 0.4 * num
>>>> else:
>>>> overtime = num - 22
>>>> x = 0.4 * 22
>>>> x += overtime * 1.4
>>>> return x

>>
>>>># Use your own brain next time

>>
>>>>Mike

>>
>>
>>>Mike,

>>
>>>I wonder if we were both just duped into helping someone with their homework...

>>
>>>Shawn

>>
>>I like to write code, so it's not a big deal when it's something so
>>simple. Still, that is beyond dumb! Nice code, by the way.
>>
>>Mike- Hide quoted text -
>>
>>- Show quoted text -

>
>
> Thanks for the help. By the way I am trying to learn the python after
> work and on weekends. If it was a dumb question, to this group, I will
> not bother you all again.
> Without help it will take me longer to learn. Thanks
>

Throw out an example of what you tried with an error message and/or
unexpected results. Ask particulars--this will keep you from giving

Sticking-my-fist-out-window-and-making-pulling-down-gesture-ly yours,

James

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/

James Stroud, Aug 21, 2007
12. ### Asun FriereGuest

Oh well since a few solutions have already been posted I thought I
might add another, just so you at the very least you have to do some
work making up your mind which one to choose. Using an incremental
approach just to be different ...

from decimal import Decimal

normal = Decimal('0.04')
over = Decimal('1.40)

def calcStopPay (stops) :
pay = Decimal('0.00')
while stops :
incr = normal if stops < 23 else over
pay += incr
stops -= 1
return pay

#testing:
for x in range(50) :
print "Stop pay for %s stops: \$%s" % (x, calcStopPay(x))

Asun Friere, Aug 21, 2007
13. ### Asun FriereGuest

On Aug 21, 5:41 pm, Asun Friere <> wrote:
> over = Decimal('1.40)

oops, that should of course be:
over = Decimal('1.40')

Asun Friere, Aug 21, 2007
14. ### Asun FriereGuest

On Aug 21, 5:51 pm, Asun Friere <> wrote:
> On Aug 21, 5:41 pm, Asun Friere <> wrote:> over = Decimal('1.40)
>
> oops, that should of course be:
> over = Decimal('1.40')

oh boy ... and it should also be
normal = Decimal('0.40')

I really need to test before posting ...

Asun Friere, Aug 21, 2007
15. ### Dennis Lee BieberGuest

On Mon, 20 Aug 2007 07:51:10 -0700, declaimed the
following in comp.lang.python:

> On Aug 20, 9:23 am, "HD1956" <> wrote:
> > This is probably a simple code. I am a truck driver who gets paid by
> > stops and cases. I am trying to figure out how to code my stop pay. I
> > get 40 cents per stop up to 22 stops, and \$1.40 per stops after that.

>
> def calc(num):
> if num < 23:
> return 0.4 * num
> else:
> overtime = num - 22
> x = 0.4 * 22
> x += overtime * 1.4
> return x
>
> # Use your own brain next time
>
> Mike

pay = min(num, 22) * 0.4 + max(num-22, 0) * 1.4
--
Wulfraed Dennis Lee Bieber KD6MOG

HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: )
HTTP://www.bestiaria.com/

Dennis Lee Bieber, Aug 21, 2007
16. ### AntGuest

On Aug 20, 11:47 pm, wrote:
....
> Thanks for the help. By the way I am trying to learn the python after
> work and on weekends. If it was a dumb question, to this group, I will
> not bother you all again.

It's not so much that it was a dumb question, but that it was asked in
a dumb way You'll get the most help in this group if you can show
some evidence that you've had a go (the size of this thread ironically
trounces that argument of course ;-) .)

It's better to learn if people give you a critique of your own attempt
at the code, rather than looking at other peoples efforts. There's a
guide on how to ask good questions here: http://www.catb.org/~esr/faqs/smart-questions.html

For what it's worth, here's a gratuitous version using generators, and
one you should come back to once you've mastered the basics of Python:

def counter(std_rate, over_rate, limit):
stops = 0
while True:
stops += 1
wage = stops * std_rate + max(0, stops - limit) * (over_rate -
std_rate)
yield stops, wage

truck = counter(0.4, 1.4, 22)

for i in range(30):
print "Stopped %s times, with accumulated wage of \$%s" %
truck.next()

--
Ant...

http://antroy.blogspot.com/

Ant, Aug 21, 2007
17. ### Steve HoldenGuest

wrote:
[...]
>
> Thanks for the help. By the way I am trying to learn the python after
> work and on weekends. If it was a dumb question, to this group, I will
> not bother you all again.
> Without help it will take me longer to learn. Thanks
>

Don't worry about it. There is also a list specifically for learners,
which you can find out about at

http://mail.python.org/mailman/listinfo/tutor

Welcome to the Python community!

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Steve Holden, Aug 21, 2007
18. ### Steve HoldenGuest

wrote:
[...]
>
> Thanks for the help. By the way I am trying to learn the python after
> work and on weekends. If it was a dumb question, to this group, I will
> not bother you all again.
> Without help it will take me longer to learn. Thanks
>

Don't worry about it. There is also a list specifically for learners,
which you can find out about at

http://mail.python.org/mailman/listinfo/tutor

Welcome to the Python community!

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Steve Holden, Aug 21, 2007
19. ### Guest

On Aug 21, 4:38 am, Ant <> wrote:
> On Aug 20, 11:47 pm, wrote:
> ...
>
> > Thanks for the help. By the way I am trying to learn the python after
> > work and on weekends. If it was a dumb question, to this group, I will
> > not bother you all again.

>
> It's not so much that it was a dumb question, but that it was asked in
> a dumb way You'll get the most help in this group if you can show
> some evidence that you've had a go (the size of this thread ironically
> trounces that argument of course ;-) .)
>
> It's better to learn if people give you a critique of your own attempt
> at the code, rather than looking at other peoples efforts. There's a
> guide on how to ask good questions here:http://www.catb.org/~esr/faqs/smart-questions.html
>
> For what it's worth, here's a gratuitous version using generators, and
> one you should come back to once you've mastered the basics of Python:
>
> def counter(std_rate, over_rate, limit):
> stops = 0
> while True:
> stops += 1
> wage = stops * std_rate + max(0, stops - limit) * (over_rate -
> std_rate)
> yield stops, wage
>
> truck = counter(0.4, 1.4, 22)
>
> for i in range(30):
> print "Stopped %s times, with accumulated wage of \$%s" %
> truck.next()
>
> --
> Ant...
>
> http://antroy.blogspot.com/

I tryed your code and got an error message #I use Wing IDE:
Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)]
>>>

Evaluating lines 1-16 from truckStops.py
<string>:7: Warning: 'yield' will become a reserved keyword in the
future
Could not execute because an error occurred:
invalid syntax: <string>, line 7, pos 19:
yield stops, wage

, Aug 21, 2007
20. ### sentientholonGuest

On Aug 21, 11:52 am, "" <> wrote:
> I tryed your code and got an error message #I use Wing IDE:
> Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)]
>
> Evaluating lines 1-16 from truckStops.py
> <string>:7: Warning: 'yield' will become a reserved keyword in the
> future
> Could not execute because an error occurred:
> invalid syntax: <string>, line 7, pos 19:
> yield stops, wage

Python 2.2.3 is three versions behind. Generators only work in 2.2 by
saying:

from __future__ import generators

And by default in anything from 2.3 on.

Fred

sentientholon, Aug 21, 2007