def setup():
packageType = 2
serviceType = 3
weight = 16
print("Expressimo Delivery Service")
charge(packageType, serviceType, weight)
def charge(package_type, service_type, weight):
cost = 0
if (package_type == 1):
print("Package : LETTER");
if (service_type == 1):
print("Service : Next day Priority")
if (weight <= 8):
cost = 12
else:
cost = 0
elif (service_type == 2):
print("Service : Next day Standard")
if (weight <= 8):
cost = 10.5
else:
cost = 0
elif (service_type == 3):
print("Service : No Service")
else:
print("Service : ERROR")
print("Weight : ",weight," Oz")
elif (package_type == 2):
print("Package : BOX")
if (service_type == 1):
print("Service : Next day Priority")
if (weight <= 1):
cost = 15.75
else:
cost = cal_service1(weight)
elif (service_type == 2):
print("Service : Next day Standard")
if (weight <= 1):
cost = 13.75
else:
cost = cal_service2(weight)
elif (service_type == 3):
print("Service : Two-days")
if (weight <= 1):
cost = 7.00
else:
cost = cal_service3(weight)
else:
print("Service : ERROR")
print("Weight :",weight,"Pound")
else:
print("Package : ERROR")
print("Charge : $",cost)
def cal_service1(weight):
firstCharge = 15.75
priority_charge = firstCharge + ((weight-1)*1.25)
return priority_charge
def cal_service2(weight):
firstCharge = 13.75;
standard_charge = firstCharge + ((weight-1)*1)
return standard_charge
def cal_service3(weight):
firstCharge = 7.00
twodays_charge = firstCharge + ((weight-1)*0.5)
return twodays_charge
setup()
Building Software Systems I & II
&
Computer Fundamentals
By Thakdanai Khunsaen
OS : Ubuntu GNOME 17.04 64-bit
วันอาทิตย์ที่ 20 กันยายน พ.ศ. 2558
Lab4x - Loan
def setup():
loanAmount = 5000
interestPercent = 12
loanTerm = 12
loan(loanAmount,interestPercent,loanTerm);
def loan(loanAmount,interestPercent,loanTerm):
print("Payment No. Principal Interest Balance Total Interest")
showValue(loanAmount,interestPercent,loanTerm)
def showValue(loanAmount,interestPercent,loanTerm):
interestRate = interestPercent/100
effectiveInterest = interestRate/12
monthlyPayment = loanAmount*(effectiveInterest/(1-pow(1+effectiveInterest, -loanTerm)))
interest = 0
totalInterest = 0
principal = 0
balance = loanAmount
term = 1
while (term <= loanTerm):
interest = balance * effectiveInterest;
principal = monthlyPayment-interest;
totalInterest += interest;
balance -= principal;
if (balance <= 0):
balance = 0
print(term," ","$%.2f"%principal," ","%.2f"%interest," ","$%.2f"%balance," ","$%.2f"%totalInterest)
term += 1
setup()
loanAmount = 5000
interestPercent = 12
loanTerm = 12
loan(loanAmount,interestPercent,loanTerm);
def loan(loanAmount,interestPercent,loanTerm):
print("Payment No. Principal Interest Balance Total Interest")
showValue(loanAmount,interestPercent,loanTerm)
def showValue(loanAmount,interestPercent,loanTerm):
interestRate = interestPercent/100
effectiveInterest = interestRate/12
monthlyPayment = loanAmount*(effectiveInterest/(1-pow(1+effectiveInterest, -loanTerm)))
interest = 0
totalInterest = 0
principal = 0
balance = loanAmount
term = 1
while (term <= loanTerm):
interest = balance * effectiveInterest;
principal = monthlyPayment-interest;
totalInterest += interest;
balance -= principal;
if (balance <= 0):
balance = 0
print(term," ","$%.2f"%principal," ","%.2f"%interest," ","$%.2f"%balance," ","$%.2f"%totalInterest)
term += 1
setup()
Lab4x - Power of Ten
def setup():
print("Power of 10\n")
power_of_ten(9)
power_of_ten(100)
def power_of_ten(power):
print("Power =",power)
if (power == 6):
print("'Million'")
elif (power == 9):
print("'Billion'")
elif (power == 12):
print("'Trillion'")
elif (power == 15):
print("'Quadrillion'")
elif (power == 18):
print("'Quintillion'")
elif (power == 21):
print("'Setillion'")
elif (power == 30):
print("'Nonillion'")
elif (power == 100):
print("'Googol'")
else:
print("'Error'")
setup()
print("Power of 10\n")
power_of_ten(9)
power_of_ten(100)
def power_of_ten(power):
print("Power =",power)
if (power == 6):
print("'Million'")
elif (power == 9):
print("'Billion'")
elif (power == 12):
print("'Trillion'")
elif (power == 15):
print("'Quadrillion'")
elif (power == 18):
print("'Quintillion'")
elif (power == 21):
print("'Setillion'")
elif (power == 30):
print("'Nonillion'")
elif (power == 100):
print("'Googol'")
else:
print("'Error'")
setup()
Lab4x - Multiplication Table
def setup():
multi_table(9)
def multi_table(number):
minMultiplier = 1
maxMultiplier = 12
while (minMultiplier <= maxMultiplier):
answer = number*minMultiplier
print(number," x ",minMultiplier," = ",answer)
minMultiplier += 1
setup()
multi_table(9)
def multi_table(number):
minMultiplier = 1
maxMultiplier = 12
while (minMultiplier <= maxMultiplier):
answer = number*minMultiplier
print(number," x ",minMultiplier," = ",answer)
minMultiplier += 1
setup()
Lab4x - Leafyear
def setup():
print("Leap Year?\n")
leapyear(1796)
leapyear(2000)
leapyear(1800)
leapyear(2015)
def leapyear(year):
if((year%4 == 0 and year%100 != 0) or (year%4 == 0 and year%100 == 0 and year%400 == 0)):
print("'",year,"' is a leap year.")
else:
print("'",year,"' isn't a leap year.")
setup()
print("Leap Year?\n")
leapyear(1796)
leapyear(2000)
leapyear(1800)
leapyear(2015)
def leapyear(year):
if((year%4 == 0 and year%100 != 0) or (year%4 == 0 and year%100 == 0 and year%400 == 0)):
print("'",year,"' is a leap year.")
else:
print("'",year,"' isn't a leap year.")
setup()
Lab4x - Grade
def setup():
cal_grade(99)
def cal_grade( score):
print("Score = ",score)
if (score <= 100 and score >= 80):
print("Grade A")
elif (score <= 79 and score >= 70):
print("Grade B")
elif (score <= 69 and score >= 60):
print("Grade C")
elif (score <= 59 and score >= 50):
print("Grade D")
elif (score < 50):
print("Grade F")
print("See you again next year.")
setup()
cal_grade(99)
def cal_grade( score):
print("Score = ",score)
if (score <= 100 and score >= 80):
print("Grade A")
elif (score <= 79 and score >= 70):
print("Grade B")
elif (score <= 69 and score >= 60):
print("Grade C")
elif (score <= 59 and score >= 50):
print("Grade D")
elif (score < 50):
print("Grade F")
print("See you again next year.")
setup()
Lab4x - Circle
def setup():
rad = 15
print("Radius =",rad)
print("Diameter =",cal_dia(rad))
print("Area =",cal_area(rad))
print("Circumference =",cal_cir(rad))
def cal_cir(rad):
cir = 2*3.14*rad
return cir
def cal_area(rad):
area = 3.14*rad*rad
return area
def cal_dia(rad):
dia = rad*2
return dia
setup()
rad = 15
print("Radius =",rad)
print("Diameter =",cal_dia(rad))
print("Area =",cal_area(rad))
print("Circumference =",cal_cir(rad))
def cal_cir(rad):
cir = 2*3.14*rad
return cir
def cal_area(rad):
area = 3.14*rad*rad
return area
def cal_dia(rad):
dia = rad*2
return dia
setup()
สมัครสมาชิก:
บทความ (Atom)