Example of Python code (C code to Python code)

Opinderjit Singh Bhella bhella at ce.mediaone.net
Tue Jun 6 22:11:46 EDT 2000


Here you go, I hope this helps. Don't forget to TAB on the ifs.


TaxRate  = 0.23
MinPay   = 300.0
RegHours = 40.0

TaxPayable = 0
Overtime = 0
OvertimeHours = 0.0

HoursWorked = float(raw_input("Please enter the hours worked per week? "))
PayRate = float(raw_input("Please 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 "The gross pay is %f" % GrossPay
print "The net pay is %f" % NetPay


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;
> }




More information about the Python-list mailing list