My "first" program
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: My "first" program

  1. #1
    Join Date
    Mar 2012
    Posts
    1

    Talking My "first" program

    This is the first, well third (but the only one that's is usefull?), program.
    I am new to programming so I figured I would post this and see if I can get some usefull feedback on how I am to do things better.
    Currently I am reading a book called "Starting Out With Python" - Tony Gaddis
    Does anyone know of a book that is a little more up to date with the current
    version of python?

    (just ignore the html tags, (how do I put the code in a box?)

    Here it is!
    <code>
    #This program calculates salary based on pay.

    #Import decimal class so rounding may be done at the end.
    import decimal

    print ("Pay Calculator\n")


    pay_rate = float(input ("Dollars per hour? --"))
    overtime_mark = float(input ("Hours to reach overtime ? --"))
    hours = float(input ("Hours this paycheck? --"))
    debit = float(input ("Debit? --"))
    #pay_rate = 0.
    #overtime_mark = 0.
    overtime_hours = 0.

    #Check if overtime or not
    if hours > overtime_mark:
    overtime_hours = hours - overtime_mark

    #Calculate pay
    overtime_pay = overtime_hours * pay_rate / 2
    sub1 = pay_rate * hours
    sub2 = sub1 + overtime_pay
    total = sub2 - debit

    ##DEBUG CODE##
    ##Displays input data
    #print("\novertime_pay" , overtime_pay)
    #print("pay_rate" , pay_rate)
    #print("overtime_mark" , overtime_mark)
    #print("overtime_hours" , overtime_hours)
    #print("hours" , hours , "\n")
    ##End input data display area

    overtime_hours_disp = overtime_hours

    #Check if overtime is more than one hour for "s" in "hours"
    if overtime_hours > 1.:
    hour_s = "hours"
    elif overtime_hours == 0:
    hour_s = ""
    overtime_hours_disp = "no"
    else: hour_s = "hour"

    #print out the results
    print ("\nYour subtotal is:\n$" + str(sub1) , "\nYou have" , str(overtime_hours_disp)
    , hour_s , "overtime for a bonus of:\n+$" + str(overtime_pay)
    , "\nYour Debit is:\n-$" + str(debit)
    , "\n\n---------------------------------------------"
    ,"\nYou should get a total of:\n$" , str(total) )
    input ("\n\nPress <ENTER> to quit")
    </code>

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,250

    Re: My "first" program

    Quote Originally Posted by aracongi
    (just ignore the html tags, (how do I put the code in a box?)
    Post your code in [code][/code] bbcode tags.

    Unfortunately, because indentation is significant in Python, I would rather not review your code until you have posted it in those bbcode tags for the indentation to be retained.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Apr 2012
    Location
    STL
    Posts
    12

    Re: My "first" program

    Quote Originally Posted by aracongi View Post
    This is the first, well third (but the only one that's is usefull?), program.
    I am new to programming so I figured I would post this and see if I can get some usefull feedback on how I am to do things better.
    Currently I am reading a book called "Starting Out With Python" - Tony Gaddis
    Does anyone know of a book that is a little more up to date with the current
    version of python?

    (just ignore the html tags, (how do I put the code in a box?)

    Here it is!
    <code>
    #This program calculates salary based on pay.

    #Import decimal class so rounding may be done at the end.
    import decimal

    print ("Pay Calculator\n")


    pay_rate = float(input ("Dollars per hour? --"))
    overtime_mark = float(input ("Hours to reach overtime ? --"))
    hours = float(input ("Hours this paycheck? --"))
    debit = float(input ("Debit? --"))
    #pay_rate = 0.
    #overtime_mark = 0.
    overtime_hours = 0.

    #Check if overtime or not
    if hours > overtime_mark:
    overtime_hours = hours - overtime_mark

    #Calculate pay
    overtime_pay = overtime_hours * pay_rate / 2
    sub1 = pay_rate * hours
    sub2 = sub1 + overtime_pay
    total = sub2 - debit

    ##DEBUG CODE##
    ##Displays input data
    #print("\novertime_pay" , overtime_pay)
    #print("pay_rate" , pay_rate)
    #print("overtime_mark" , overtime_mark)
    #print("overtime_hours" , overtime_hours)
    #print("hours" , hours , "\n")
    ##End input data display area

    overtime_hours_disp = overtime_hours

    #Check if overtime is more than one hour for "s" in "hours"
    if overtime_hours > 1.:
    hour_s = "hours"
    elif overtime_hours == 0:
    hour_s = ""
    overtime_hours_disp = "no"
    else: hour_s = "hour"

    #print out the results
    print ("\nYour subtotal is:\n$" + str(sub1) , "\nYou have" , str(overtime_hours_disp)
    , hour_s , "overtime for a bonus of:\n+$" + str(overtime_pay)
    , "\nYour Debit is:\n-$" + str(debit)
    , "\n\n---------------------------------------------"
    ,"\nYou should get a total of:\n$" , str(total) )
    input ("\n\nPress <ENTER> to quit")
    </code>
    This should help. I hope you find something you like.
    http://www.amazon.com/Python-Languag...F8&node=285856

    I had trouble with Visual Basic and I bought a book and it helped me a bunch thanks to amazon

  4. #4
    Join Date
    Apr 2012
    Posts
    29

    Re: My "first" program

    PHP Code:
    from twisted.web import serverresource
    from twisted
    .internet import reactor
    class HelloResource(resource.Resource):
        
    numberRequests=0
        def render_GET
    (self,request):
            
    self.numberRequests+=1
            request
    .setHeader("content-type","text/plain")
            return 
    "Hello, you have called me "+str(self.numberRequests)+" times\n"
    reactor.listenTCP(56565,server.Site(HelloResource()))
    reactor.run() 
    My first program, mind you that it runs only on python 2.7 or lower, since at present there is no twisted library included in later versions

    Issue
    C:\> python thefile.py

    then run your web browser on the established host with the port number 56565. Refresh it to see the message.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center