def setup():
cal_BMI(59,175)
def cal_BMI(w,h): #weight
d=h/100
print("BMI : ",w/(d*d))
print("Weight : ",w)
print("Height : ",h)
setup() # call setup
วันพฤหัสบดีที่ 17 กันยายน พ.ศ. 2558
Lab4x : GRADE
def setup():
cal_grade(100)
def cal_grade(score): #grade
print("Score :",score)
if score<=100 and score>=0:
if score>=80:
print("Grade A")
elif score>=70:
print("Grade B")
elif score>=60:
print("Grade C")
elif score>=50:
print("Grade D")
else:
print("Grade F")
else:
print("Inccorect")
setup() # call setup
cal_grade(100)
def cal_grade(score): #grade
print("Score :",score)
if score<=100 and score>=0:
if score>=80:
print("Grade A")
elif score>=70:
print("Grade B")
elif score>=60:
print("Grade C")
elif score>=50:
print("Grade D")
else:
print("Grade F")
else:
print("Inccorect")
setup() # call setup
Lab4x : sum
def setup():
sum(10)
def sum(n): #sum
i=1
sum=0
while i<=n:
if i==1:
print(i,end=' ')
else:
print("+",i,end=' ')
sum+=i
i+=1
print("=",sum)
setup() # call setup
sum(10)
def sum(n): #sum
i=1
sum=0
while i<=n:
if i==1:
print(i,end=' ')
else:
print("+",i,end=' ')
sum+=i
i+=1
print("=",sum)
setup() # call setup
Lab4x : leapyear
def setup():
leap(1976)
def leap(number): #leap year
if (number%4==0 and number%100!=0) or (number%4==0 and number%100==0 and number%400==0):
print("Year :",number,"a Leap Year")
else:
print("Year :",number,"not a Leap Year")
setup() # call setup
leap(1976)
def leap(number): #leap year
if (number%4==0 and number%100!=0) or (number%4==0 and number%100==0 and number%400==0):
print("Year :",number,"a Leap Year")
else:
print("Year :",number,"not a Leap Year")
setup() # call setup
Lab4x : power of ten
def setup():
print (power(12))
def power(number):
texts=str(number)+" : "
if number==6:
texts+="Million";
elif number==9:
texts+="Billion";
elif number==12:
texts+="Trillion";
elif number==15:
texts+="Quadrillion";
elif number==18:
texts+="Quintillion";
elif number==21:
texts+="Sextillion";
elif number==30:
texts+="Nomillion";
elif number==100:
texts+="Googol";
else:
texts+="No Name";
return texts;
setup()
print (power(12))
def power(number):
texts=str(number)+" : "
if number==6:
texts+="Million";
elif number==9:
texts+="Billion";
elif number==12:
texts+="Trillion";
elif number==15:
texts+="Quadrillion";
elif number==18:
texts+="Quintillion";
elif number==21:
texts+="Sextillion";
elif number==30:
texts+="Nomillion";
elif number==100:
texts+="Googol";
else:
texts+="No Name";
return texts;
setup()
Lab4x : Multiplication Table
def setup():
multable(1, 12, 5)
def multable(i,row,N):
mul=0
while (i<=row):
mul = N * i
print(N," x ",i," = ",mul)
i += 1
setup()
multable(1, 12, 5)
def multable(i,row,N):
mul=0
while (i<=row):
mul = N * i
print(N," x ",i," = ",mul)
i += 1
setup()
Lab4x : Circle calc
import math
def setup():
cal_cir(3)
def cal_cir(r): #radius
print("area : ",math.pi*r*r)
print("Circumference : ",2*math.pi*r)
setup()
def setup():
cal_cir(3)
def cal_cir(r): #radius
print("area : ",math.pi*r*r)
print("Circumference : ",2*math.pi*r)
setup()
Lab4x : Prime sum
def setup():
print (sumprime(11))
def sumprime(n): #sum prime
i=2
sum=0
while i<=n:
if i==2:
print(i,end=' ')
sum+=2
elif prime(i):
print("+",i,end=' ')
sum+=i
i+=1
print("=",sum)
def prime(x): # check if prime
i=2
prime=True
while (i<x):
if x%i==0:
prime=False
i+=1
if x==1:
prime=False
return prime
setup() #call setup
print (sumprime(11))
def sumprime(n): #sum prime
i=2
sum=0
while i<=n:
if i==2:
print(i,end=' ')
sum+=2
elif prime(i):
print("+",i,end=' ')
sum+=i
i+=1
print("=",sum)
def prime(x): # check if prime
i=2
prime=True
while (i<x):
if x%i==0:
prime=False
i+=1
if x==1:
prime=False
return prime
setup() #call setup
Lab4x : Loan
# "{:.2f}".format
def setup():
loan(5000,0.12,1); #5000baht 12percent 1year
def loan(amt,rate,yr):
month=yr*12;
ratepm=rate/12; #rate per month per year
ppm=amt * ( ratepm / (1 - pow(1 + ratepm,-month))); #(pri+interest)
pri=ppm; #principal
unpaid=amt; #unpaid
total_interest=0;
i=1;
print("No. Interest Principal Unpaid total interest");
while (i<=month):
print(i,end=' '); #NO.
print(" ","{:10.2f}".format(ratepm*unpaid),end=' '); #interest 10.2
total_interest+=ratepm*unpaid;
pri=ppm-(ratepm*unpaid);
unpaid-=pri;
if (unpaid<0):
unpaid=0
print(" ","{:.2f}".format(pri),end=' ') #principal
print(" ","{:.2f}".format(unpaid),end=' ') #unpaid
print(" ","{:.2f}".format(total_interest),end=' ')#total_interest
print()
i+=1
setup()
Vending Machine Simulator
Changelog : [22/9/2558]
- add limit coin to 999
- fix coin bug
- tidy show text
Changelog : [27/9/2558]
- Add Coin Effect
- Add Show Change when cancel
วันอาทิตย์ที่ 13 กันยายน พ.ศ. 2558
Lab4x : Delivery Charge
def setup():
print("Parameter1 -> 1=Letter 2=Box")
print("Parameter2 -> 1=Next Day Priority 2=Next Day Standard 3=2-DAY")
print("Parameter3 -> Weight (oz for letter / kg for box)")
print(delivery(1,1,8))
def delivery(pktype,svtype,weight):
chargebox=0
text1=""
# PACKAGE TYPE1
if (pktype==1):
if (svtype==1):
if (weight<=8 and weight>0):
text1="CHARGE :$ 12.00"
else:
text1="Not Avaliable - incorrect weight"
elif (svtype==2):
if (weight<=8 and weight>0):
text1="CHARGE :$ 10.50"
else:
text1="Not Avaliable - incorrect weight"
elif (svtype==3):
text1="Not Avaliable"
#PACKAGE TYPE2
if (pktype==2):
if (svtype==1):
if (weight>0):
chargebox=15.75+(weight-1)*1.25
text1="CHARGE :$ "+chargebox
else:
text1="Not Avaliable - incorrect weight"
elif (svtype==2):
if (weight>0):
chargebox=13.75+weight-1
text1="CHARGE :$ "+chargebox
else:
text1="Not Avaliable - incorrect weight"
elif (svtype==3):
if (weight>0):
chargebox=7.00+(weight-1)*0.5;
text1="CHARGE :$ "+chargebox
else:
text1="Not Avaliable - incorrect weight"
return text1
setup()
print("Parameter1 -> 1=Letter 2=Box")
print("Parameter2 -> 1=Next Day Priority 2=Next Day Standard 3=2-DAY")
print("Parameter3 -> Weight (oz for letter / kg for box)")
print(delivery(1,1,8))
def delivery(pktype,svtype,weight):
chargebox=0
text1=""
# PACKAGE TYPE1
if (pktype==1):
if (svtype==1):
if (weight<=8 and weight>0):
text1="CHARGE :$ 12.00"
else:
text1="Not Avaliable - incorrect weight"
elif (svtype==2):
if (weight<=8 and weight>0):
text1="CHARGE :$ 10.50"
else:
text1="Not Avaliable - incorrect weight"
elif (svtype==3):
text1="Not Avaliable"
#PACKAGE TYPE2
if (pktype==2):
if (svtype==1):
if (weight>0):
chargebox=15.75+(weight-1)*1.25
text1="CHARGE :$ "+chargebox
else:
text1="Not Avaliable - incorrect weight"
elif (svtype==2):
if (weight>0):
chargebox=13.75+weight-1
text1="CHARGE :$ "+chargebox
else:
text1="Not Avaliable - incorrect weight"
elif (svtype==3):
if (weight>0):
chargebox=7.00+(weight-1)*0.5;
text1="CHARGE :$ "+chargebox
else:
text1="Not Avaliable - incorrect weight"
return text1
setup()
สมัครสมาชิก:
บทความ (Atom)
commit เพิ่มเติม : เพื่ม userstory, bookmark
>> add userstory ทำการเพิ่ม userstory ใน functional tests >> add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...
-
1 2 3 4 5 6 7 8 9 def setup (): print (d2b( 8 )) def d2b (num): x = "" while num > 0 : x = str ( int (n...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 def test_layout_and_styling ( self ): # Edith goes to the home page self . brow...
-
การใช้ template inheritence คือการสืบทอดเทมเพลต เพื่อให้ไม่ต้องเขียนโค้ดหน้าเว็บๆซ้ำๆ เราจะมีหน้าหลักอันเดียว (base.html or parent) ภายในนั...