程序代写代做代考 Programming Exercise 3-1

Programming Exercise 3-1

Programming Exercise 5-2
# Global constants for the state and county tax rates

STATE_TAX_RATE = 0.05

COUNTY_TAX_RATE = 0.025

# maindef

def main():

# Local variables

purchase = 0.0

stateTax = 0.0

countyTax = 0.0

# Get the amount of the purchase

purchase = float(input(‘Enter the purchase amount: ‘))

# Calculate the state tax

stateTax = purchase * STATE_TAX_RATE

# Calculate the county tax

countyTax = purchase * COUNTY_TAX_RATE

# Print information about the sale

showSale(purchase, stateTax, countyTax)

# The showSale function accepts purchase, stateTax,

# countyTax as arguments and prints the equivalent

# total sale information.

def showSale (purchase, stateTax, countyTax):

#local variables

totalTax = 0.0

totalSale = 0.0

totalTax = stateTax + countyTax

totalSale = purchase + totalTax

print (‘Purchase amount:’, format(purchase, ‘.2f’))

print (‘State tax:’, format(stateTax, ‘.2f’))

print (‘County tax:’, format(countyTax, ‘.2f’))

print (‘Total tax:’, format(totalTax, ‘.2f’))

print (‘Sale total:’, format(totalSale, ‘.2f’))

# Call the main function.

main()

_1254835704.vsd

main()
getPurchase
(purchase)
showSale
(purchase, stateTax,
countyTax)
End
Declare
Purchase, stateTax,
countyTax
getPurchase
(Ref inputPurchase)
Return
Display “Enter
the purchase
amount.”
Input
inputPurchase
showSale
(purchase, stateTax,
countyTax)
Return
Set totalTax =
stateTax +
countyTax
Display
“”Purchase Amount: $”, purchase
“State Tax: “, stateTax
“County Tax: “, countyTax
“Total Tax: “, totalTax
“Sale total: “, totalSale
Declare
totalTax, totalSale
Global Constant Real
STATE_TAX_RATE
COUNTY_TAX_RATE
setStateTax
(purchase, stateTax)
setCountyTax
(purchase, countyTax)
setStateTax
(Ref stateTax)
Return
Set stateTax =
purchase *
STATE_TAX_RATE
Set countyTax
(Ref countyTax)
Return
Set countyTax =
purchase *
COUNTY_TAX_RATE
Set totalSale =
purchase +
totalTax

main()

getPurchase
(purchase)

showSale
(purchase, stateTax, countyTax)

End

Declare
Purchase, stateTax, countyTax

Set totalSale =
purchase + totalTax

getPurchase
(Ref inputPurchase)

Input
inputPurchase

showSale
(purchase, stateTax, countyTax)

Return

Return

Display “Enter the purchase amount.”

Set totalTax =
stateTax + countyTax

Display
“”Purchase Amount: $”, purchase
“State Tax: “, stateTax
“County Tax: “, countyTax
“Total Tax: “, totalTax
“Sale total: “, totalSale

Declare
totalTax, totalSale

Global Constant Real STATE_TAX_RATE COUNTY_TAX_RATE

setStateTax
(purchase, stateTax)

setCountyTax
(purchase, countyTax)

setStateTax
(Ref stateTax)

Return

Set countyTax
(Ref countyTax)

Set stateTax =
purchase * STATE_TAX_RATE

Return

Set countyTax =
purchase * COUNTY_TAX_RATE