Blog 內嵌程式碼四

樣式一:

Source file
 1 # Please fix the BUG
 2 tall = input("what is your height? (for example, 1.72)")
 3 weight = input("what is your weight? (for example, 60)")
 4 
 5 bmii = weight/(tall*tall)
 6 print ("Your BMI is", bmii)


樣式二:
Source file
 1 # Please fix the BUG
 2 tall = input("what is your height? (for example, 1.72)")
 3 weight = input("what is your weight? (for example, 60)")
 4 
 5 bmii = weight/(tall*tall)
 6 print ("Your BMI is", bmii)


樣式三:

Source file
 1 // 按鍵鋼琴,利用按鈕播放音階
 2  2 const int speaker=2;
 3  3 const int sw[8]={4,5,6,7,8,9,10,11} ;
 4  4 const int frequency[8]={523,587,659,694,784,880,988,1046};
 5  5 int i ;
 6  6 int val ;
 7  7 
 8  8 void setup() {
 9  9   // put your setup code here, to run once:
10 10   for(int i=0;i<8;i++) 
11 11      pinMode(sw[i],INPUT) ;
12 12 
13 13 }
14 14 
15 15 void loop() {
16 16   // put your main code here, to run repeatedly:
17 17   for(int i=0;i<8;i++) {
18 18     val = digitalRead(sw[i]) ;
19 19     
20 20     if (val==1){
21 21         tone(speaker,frequency[i],100) ;
22 22      }
23 23    }
24 24 
25 25 }


樣式四:

在Blog 貼上程式碼二

首先我們示範第一種在Blog內嵌程式碼的方法,外觀如下所見。

sum = 0
for i in range(11):
    sum += i
print("總數是 {}".format(sum))