Example of Python code (C code to Python code)
Ken Seehof
12klat at sightreader.com
Tue Jun 6 22:55:46 EDT 2000
That's easy. Just delete all variable declarations and puctuation.
TaxRate=.23
MinPay=300
RegHours=40
def main():
TaxPayable=0
Overtime=0
OvertimeHours=0
HoursWorked = input("Please enter the hours worked per week? ")
PayRate = input("\nPlease enter the rate of pay? ")
if HoursWorked>RegHours:
OvertimeHours =HoursWorked-RegHours
Overtime = (OvertimeHours)*(PayRate*1.5)
GrossPay = ((HoursWorked-OvertimeHours)*PayRate)+Overtime
if (GrossPay>MinPay):
TaxPayable = (GrossPay-MinPay)*TaxRate
NetPay = (GrossPay-TaxPayable)
print "\nThe gross pay is %f" % GrossPay
print "The net pay is %f" % NetPay
main()
The gross pay is 85.000000
The net pay is 85.000000
Please make check payable to:
Ken Seehof
4965 Cree Way
Boise, ID 83709
:-)
Robin Porter wrote:
> Could someone please give me an example of some Python code. I am just new
> to this language and would appreciate if you could re-write this simple
> piece of C code in Python.
>
> Thank you,
>
> Robin
>
> #include "stdafx.h"
> #include <stdio.h>
> #include <math.h>
>
> float
> HoursWorked,PayRate,Overtime,IncomeTaxes,GrossPay,NetPay,TaxPayable,Overtime
> Hours;
>
> const float TaxRate=.23;
> const MinPay=300;
> const RegHours=40;
>
> main()
> {
>
> TaxPayable=0;
> Overtime=0;
> OvertimeHours=0;
>
> printf("\nPlease enter the hours worked per week? ");
> scanf("%f",&HoursWorked);
>
> printf("\nPlease enter the rate of pay? ");
> scanf("%f",&PayRate);
>
> if (HoursWorked>RegHours)
> {
> OvertimeHours =HoursWorked-RegHours;
> Overtime = (OvertimeHours)*(PayRate*1.5);
> }
>
> GrossPay = ((HoursWorked-OvertimeHours)*PayRate)+Overtime;
>
> if (GrossPay>MinPay)
> {
> TaxPayable = (GrossPay-MinPay)*TaxRate;
> }
>
> NetPay = (GrossPay-TaxPayable);
>
> printf("\nThe gross pay is %f",GrossPay);
> printf("\nThe net pay is %f",NetPay);
>
> return 0;
> }
--
Ken Seehof
kens at sightreader.com
starship.python.net/crew/seehof
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20000606/621f6d48/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 12klat.vcf
Type: text/x-vcard
Size: 343 bytes
Desc: Card for Ken Seehof
URL: <http://mail.python.org/pipermail/python-list/attachments/20000606/621f6d48/attachment.vcf>
More information about the Python-list
mailing list