App Inventor 2 入門範例:變數與溫度轉換

格式
pdf
大小
4.04 MB
頁數
27
作者
gracelu
收藏 ⬇️ 下載檔案
提示: 文件格式为 pdf,轉換可能會出現排版或格式的些許差異,請以實際檔案為準。
此檔案建立於 2015-06-01,离现在 10 145 天,建議確認內容是否仍然適用。
PDF 加载中...
background image

App inventor 2 範例                       

小盧  105/5/30   

  1 

 

變數用來暫存資料,需提供讀取與存入變數功能 

 

讀取變數

 

 

存入變數

 

 

宣告全域變數

    若在 screen1 宣告的全域變數,screen1 任何位置可存取 

 

例如宣告 i 變數初值為 0 

 

 

宣告區域變數

,僅在該區域範圍內。 

 

 

如要表達 vb 的 sum=sum+num       

 

 

如要表達 vb 的 textbox1.text=I       

 

 

全域變數範例 

 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  2 

 

範例 1:華氐轉攝氏 

 

 

Textbox2.text=(textbox1.text-32)*5/9 

=============================================================================== 

範例 2:買飲料 

飲料 1 罐 15 元,一打(12 罐)150 元,假設消費者不會多買,不足一打以單罐計算,請計算購買數

量所需的金額。 

 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  3 

 

範例 3:餐點訂購系統 

雞腿飯 90 元,排骨飯 70 元,燒鴨飯 80 元,依使用者輸入數量,計算總金額與找零。 

 

Textbox1 雞腿飯的數量 Textbox2 排骨飯的數量 Textbox3 燒鴨飯的數量 

 

總金額(textbox4) Textbox4.text=90*textbox1.text    + 70* textbox2.text    + 80 * textbox3.text 
付錢(textbox5)    找零(textbox6) Textbox6.text=textbox5.text – textbox4.text 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  4 

 

範例 4:外幣兌換新台幣 

 

 

 

 

 

 

 

=============================================================================== 

範例 5:成績結果判斷 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  5 

 

範例 6:判斷奇數或偶數 

 

 

======================================================================= 

範例 7:  帳號密碼驗證 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  6 

 

範例 8:計算點數 

 

 

 

 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  7 

 

Vb 的 msgbox 格式參考 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  8 

 

範例 9:成績與等第 

90-100 優等 

80-89 甲等 

70-79 乙等 

60-69 丙級 

59 丁等 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  9 

 

範例 10:BMI 計算 

BMI<18 體重過輕 

18<=BMI<24 體重正常 

24<=BMI<27 稍微過重 

27<=BMI<30 輕度肥胖 

30<=BMI      肥胖 

 

 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  10 

 

範例 11:電費計算 

 

 

 

 

度數                        每度價格                    累進差額 

0<X<=100                      2           

                    0 

100<X<=300                      3           

                100 

300<X<=500                      4           

                400 

500<X<=700                      5           

                900 

700<X                                6           

              1600 

background image

App inventor 2 範例                       

小盧  105/5/30   

  11 

 

範例 12:產生 1-10 數字 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  12 

 

範例 13:求階層 

 

 

佈置 

 

 

 

 

Fac                  1 

                         

Fac                  1*2 

                         

 

Fac                  1*2*3 

                         

Fac                  1*2*3*4 

                         

fac 

 

24 

120 

background image

App inventor 2 範例                       

小盧  105/5/30   

  13 

 

範例 14:1+2+…..+N 

 

 

 

 

 

 

 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  14 

 

範例 15:求因數 

 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  15 

 

範例 16:九九乘法表 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  16 

 

範例 17:質數判斷 

 

 

預設 flag=true 
當按下 button1 時 flag=true,當 flag=true 表示 n 是質數 
Flag=false 表示非質數 

background image

App inventor 2 範例                       

小盧  105/5/30   

  17 

 

範例 18:  印圖形 

 

畫面佈置 

 

 

程式碼說明 

聰明的你(妳)能印出下三角形嗎?動手做做看吧 

background image

App inventor 2 範例                       

小盧  105/5/30   

  18 

 

 

 

 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  19 

 

範例 19:樂透開獎 

 

 

 

 

產生所有可以開獎的數字 
產生  1-textbox1.text 個數值 
加入  num 陣列,例 1-49 

產生  TEXTBOX2.TEXT 個數值 
每次從陣列中排出一個數 x 
將 x 放入 lotto 陣列 
Lotto 陣列是已開獎的號碼 

 
Remove list item 將陣列 num 中
的數字 x 移除 

 
顯示陣列 lotte 中的所有元素 

每一次使用先清空 textbox3.text 

初始化 num 為空陣列 

初始化 lotto 為空陣列 

background image

App inventor 2 範例                       

小盧  105/5/30   

  20 

 

範例 20:spinner 選單練習

 

 

 

 

         

 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  21 

 

 

 

 

佈置 

 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  22 

 

 

 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  23 

 

範例 21:Listpicker 練習 

 

 

     

 

 
 

 

 

 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  24 

 

   

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  25 

 

範例 22:自訂函式 BMI 練習 

 

 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  26 

 

範例 24:自訂函式猜數字練習 

 

 

 

background image

App inventor 2 範例                       

小盧  105/5/30   

  27 

 

範例 25:自訂函式求質數練習 

 

 

 

版權說明: 檔案資源由用戶上傳,僅供學習交流使用,尊重著作權。 若您認為內容涉及侵權,請點擊「侵權舉報」提交相關資料,我們將儘快核實並處理。