|
-
March 7th, 2012, 10:22 PM
#1
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>
-
March 8th, 2012, 01:44 AM
#2
Re: My "first" program
 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.
-
April 20th, 2012, 02:30 PM
#3
Re: My "first" program
 Originally Posted by aracongi
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
-
May 29th, 2012, 09:37 PM
#4
Re: My "first" program
PHP Code:
from twisted.web import server, resource 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|