#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    17
    Rep Power
    0

    Checking my noob code :P


    Hi just needing help looking what the problem is in my code, when i compile it it just says syntax error and i cant figure it why, much appreciated.

    def lab3q3(org, rate, hourstake, hours):

    if hours > hourstake:
    for i < (hours/hourstake):
    return org*rate*(hours/hourstake)

    still a noob at python, if you need any extra information about this just post please, and thank you very much!
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Iran
    Posts
    148
    Rep Power
    139
    This is not how you write a for loop in python.

    Take a look at

    http://docs.python.org/release/3.2.3/reference/compound_stmts.html#for

    in order to understand how it works.


    Regards,
    Dariyoosh
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Joensuu, Finland
    Posts
    428
    Rep Power
    66
    Originally Posted by dariyoosh
    This is not how you write a for loop in python.
    Actually it looks like there’s not even a need for a “for” loop.

    Code:
    def lab3q3(org, rate, hourstake, hours):
        if hours > hourstake:
            return org*rate*(hours/hourstake)
        else:
            # return something else here
    My armada: openSUSE 13.1 (home desktop, home laptop), Crunchbang Linux 11 (mini laptop, work laptop), Android 4.2.1 (tablet)
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,704
    Rep Power
    480

    wanna bet


    hours/hourstake may be an integer division. Beware!
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo