Hi,
In this post i attached my lecture 3 which describes chapter 3 and 6. but here, i am going to post practice questions and tutorial for chapter 3 only
here you can find lecture slides,
Programming Exercises
you can find these exercise questions at the end of the chapter 3 in this book.
Here, i am going to write the answers for each question.
1. Kilometer Converter
Write a program that asks the user to enter a distance in kilometers, and then converts that distance to miles. The conversion formula is as follows:
Miles = Kilometers * 0.6214
answer :-
2. How Much Insurance?
4. Property Tax
In this post i attached my lecture 3 which describes chapter 3 and 6. but here, i am going to post practice questions and tutorial for chapter 3 only
here you can find lecture slides,
Programming Exercises
you can find these exercise questions at the end of the chapter 3 in this book.
Here, i am going to write the answers for each question.
1. Kilometer Converter
Write a program that asks the user to enter a distance in kilometers, and then converts that distance to miles. The conversion formula is as follows:
Miles = Kilometers * 0.6214
answer :-
def main():
distance = float(input("Enter the kilometer that you want to convert : "))
converter(distance)
def converter(value):
Miles = value * 0.6214
print("Distance of kilo",value,", in males is :",format(Miles , ',.2f'))
main()
Many financial experts advise that property owners should insure their homes or buildings for at least 80 percent of the amount it would cost to replace the structure. Write a program that asks the user to enter the replacement cost of a building and then displays the minimum amount of insurance he or she should buy for the property.
answer :-
def main():
replacementCost = float(input("Enter the amount of replacement cost of building or property : "))
minimumInsurance = calculateInsurance(replacementCost)
print("minimum amount of insurance you should buy forthe property : $"+ \
str(minimumInsurance))
def calculateInsurance(amount):
insuranceCost = amount * .8
return format(insuranceCost , ',.2f')
main()
3. Automobile Costs
Write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses, and the total annual cost of these expenses.
answer :-
def main():
loanCost = float(input("Enter the monthly cost for loan payment : "))
insuranceCost = float(input("Enter the monthly cost for insurance : "))
gasCost = float(input("Enter the monthly cost for gas : "))
oilCost = float(input("Enter the monthly cost for oil : "))
tiresCost = float(input("Enter the monthly cost for tries : "))
maintenanceCost = float(input("Enter the monthly cost for maintenance : "))
totalMonthlyCost,annualCost = calculateCost(loanCost,insuranceCost,gasCost,oilCost,tiresCost,maintenanceCost)
print("total monthly expenses : $"+str(totalMonthlyCost))
print("total annual expenses : $"+str(annualCost))
def calculateCost(a,b,c,d,e,f):
monthlyExpense = a + b + c + d + e + f
annualExpense = monthlyExpense * 12
return format(monthlyExpense , ',.2f'),format(annualExpense , ',.2f')
main()
A county collects property taxes on the assessment value of property, which is 60 percent of the property’s actual value. For example, if an acre of land is valued at $10,000, its assessment value is $6,000. The property tax is then 64¢ for each $100 of the assessment value. The tax for the acre assessed at $6,000 will be $38.40. Write a program that asks for the actual value of a piece of property and displays the assessment value and property tax.
answer :-
def main():
actualValue = float(input("Enter the actual value of the property : "))
assessmentValue,propertyTax = calculateTax(actualValue)
print("assessment value of the property : $"+ \
str(assessmentValue))
print("property tax : $"+ \
str(propertyTax))
def calculateTax(amount):
assessmentAmount = amount * .6
taxAmount = assessmentAmount * .0064
return format(assessmentAmount , ',.2f') ,format(taxAmount , ',.2f')
main()
5. Body Mass Index
Write a program that calculates and displays a person’s body mass index (BMI). The BMI is often used to determine whether a person is overweight or underweight for his or her height. A person’s BMI is calculated with the following formula:
BMI = weight * 703 / height * height
where weight is measured in pounds and height is measured in inches.
answer :-
def main():
weight = float(input("Enter the weight (in pound) : "))
height = float(input("Enter the height (in inches) : "))
bmi = calculateBMI(weight , height)
print("A person's Body Mass Index :",bmi)
def calculateBMI(w,h):
bmi = w * (703 / h ** 2)
return format(bmi , ',.2f')
main()
6. Calories from Fat and Carbohydrates
A nutritionist who works for a fitness club helps members by evaluating their diets. As part of her evaluation, she asks members for the number of fat grams and carbohydrate grams that they consumed in a day. Then, she calculates the number of calories that result from the fat, using the following formula:
calories from fat = fat grams x 9
Next, she calculates the number of calories that result from the carbohydrates, using the following formula:
calories from carbs = carb grams x 4
The nutritionist asks you to write a program that will make these calculations.
answer :-
def main():
fatGrams = int(input("Enter the number of fat grams you consumed in a day : "))
carboGrams = int(input("Enter the number of carbohydrate grams you consumed in a day : "))
caloriesFromFat,caloriesFromcarbo = calculateCalories(fatGrams , carboGrams)
print("number of calories that result from fat :",caloriesFromFat)
print("number of calories that result from carbohydrate :",caloriesFromcarbo)
def calculateCalories(f,c):
fat = f * 9
carbs = c * 4
return fat,carbs
main()
7. Stadium Seating
There are three seating categories at a stadium. For a softball game, Class A seats cost $15, Class B seats cost $12, and Class C seats cost $9. Write a program that asks how many tickets for each class of seats were sold, and then displays the amount of income generated from ticket sales.
answer :-
def main():
classA = int(input("how many tickets you want from class A : "))
classB = int(input("how many tickets you want from class B : "))
classC = int(input("how many tickets you want from class C : "))
totalIncome = calculateIncome(classA,classB,classC)
print("amount of income generated from ticket sales :",totalIncome)
def calculateIncome(a,b,c):
income = a*15 + b*12 + c*9
return income
main()
8. Paint Job Estimator
A painting company has determined that for every 115 square feet of wall space, one gallon of paint and eight hours of labor will be required. The company charges $20.00 per hour for labor. Write a program that asks the user to enter the square feet of wall space to be painted and the price of the paint per gallon. The program should display the following data:
• The number of gallons of paint required
• The hours of labor required
• The cost of the paint
• The labor charges
• The total cost of the paint job
answer :-
def main():
squreFeed = int(input("Enter the squre feed : "))
gallonPerPaintPrice = int(input("Enter the price of a gallon paint : "))
print("number of gallons of paint :",format(requiredPaint(squreFeed) , '.2f'))
print("number of labor hour required : ",format(requiedLabourHour(squreFeed) , '.2f'))
costOfPaint = requiredPaint(squreFeed) * gallonPerPaintPrice
print("the cost of paint : $",format(costOfPaint , '.2f'),sep ="")
LabourCharge = requiedLabourHour(squreFeed) * 20
print("the labour charge : $",format(LabourCharge , '.2f'),sep ="")
totalCost = costOfPaint + LabourCharge
print("the total cost of the paint job : $",format(totalCost , '.2f'),sep="")
def requiredPaint(squreFeed):
requirePaint = squreFeed / 115
return requirePaint
def requiedLabourHour(squreFeed):
requirHour = requiredPaint(squreFeed) * 8
return requirHour
main()
9. Monthly Sales Tax
A retail company must file a monthly sales tax report listing the total sales for the month, and the amount of state and county sales tax collected. The state sales tax rate is 4 percent and the county sales tax rate is 2 percent. Write a program that asks the user to enter the total sales for the month. From this figure, the application should calculate and display the following:
• The amount of county sales tax
• The amount of state sales tax
• The total sales tax (county plus state)
answer :-
def main():
amountPurchase = float(input("Enter the amount of purchase : "))
print("total amount of purchase is :",amountPurchase)
stateSaleTax = stateSalesTax(amountPurchase)
countySaleTax = countySalesTax(amountPurchase)
print("state sale tax :", format(stateSaleTax , ',.2f'))
print("county sale tax :",format(countySaleTax , ',.2f'))
totalSaleTax = stateSaleTax + countySaleTax
print("total sale tax :",format(totalSaleTax, ',.2f'))
totalSale = amountPurchase + totalSaleTax
print("total sale :",format(totalSale, ',.2f'))
def stateSalesTax(amountPurchase):
stateTax = amountPurchase * 0.02
return stateTax
def countySalesTax(amountPurchase):
countyTax = amountPurchase * 0.04
return countyTax
main()
i will post chapter 6 very soon..........
No comments:
Post a Comment