發表文章

莊俊祥python集合set元組tuple清單或串列list迴圈輸出str,int

圖片
W3Schools截圖 W3Schools程式碼 #莊俊祥 集合{},清單[],元組(),字典{key:value} s = {"台積電", "鴻海", "聯發科", "中華電", "台塑化"} t = ("台積電", "鴻海", "聯發科", "中華電", "台塑化") list = ["台積電", "鴻海", "聯發科"] d = {2330:"台積電", 2317:"鴻海", 2454:"聯發科"} print("s型態" + str(type(s))) print("t型態" + str(type(t))) print("d型態" + str(type(d))) print("t型態" + str(type(list))) #字串與字串+ i = 0 for a in t: i = i + 1 print("台灣市場價格第" + str(i) + "大公司是") print(" " + a) print("聯發科的位置" + str(t.index("聯發科"))) '''python大區塊的註解,前後用三個引號 str 轉成字串 int 轉成數字 ''' w3schools元組tuples的方法 Python has two built-in methods that you can use on tuples. Method Description count() Returns the number of times a specified value occurs in a tuple index() Searches the tuple for a speci...

莊俊祥python字典

圖片
w3schols截圖 w3schols練習程式碼 a = { #台灣股票市場價值最大,莊俊祥python 2330: "台積電", 2317: "鴻海", 2454: "聯發科", 2412: "中華電", 6505: "台塑化" } print(a) print(a[6505]) print(a.get(2330))#功能同 a[2330] print(a.keys()) #keys()方法列出key搜尋鍵 print(a.values()) #keys()方法列出values值 b = a.copy() print("列出b " + str(b)) print(b[2317]) print(b.clear()) a.update({2308: "台達電"}) print(a.values()) print("用迴圈列出字典a的所有值") for t in a: print(a[t]) w3schols字典用法 Method 方法 Description說明 clear() 移除字典的Removes all the elements項目(items) from the dictionary copy() Returns a copy of the dictionary fromkeys() Returns a dictionary with the specified keys and value get() Returns the value of the specified key items() Returns a list containing a tuple for each key value pair keys() Returns a list containing the dictionary's keys pop() 移除某個項目Removes the element with the specified key popitem() 移除最後一個Removes the last inserted key-value pair setd...

莊俊祥python,print,input,字串[::-1]

圖片
w3school學習python vs code編寫python #莊俊祥的第一個python程式2023/2/20 print("你在跟我哈啦嗎?") #python輸出比Java簡單太多 a = "你在跟我哈啦,狗吃屎" #python指令結尾不需要;分號 b = '貓抓鼠,師父開撈駛來時' #phthon字串單引雙引號都可 print(a) print(b) c = a[1:5:] #取字串a的第1到5(不含),從0開始 print(c) c = a[::-1] print(c) a = input("自己輸入字串:") print("你輸入:"+a) print("反過來:"+a[::-1])

D11117223莊俊祥JavaScript將輸入的字串顛倒輸出程式碼

圖片
莊俊祥輸入字串: 程式碼

莊俊祥Java內建方法length(),charAt() 使用微軟VS Code開發環境

圖片
Java程式碼 /*整合開發環境IDE, Integrated Developmnet Environment*/ public class Main { /*莊俊祥w3schools內建方法length,charAt*/ public static void main(String[] args) { String a = "中華民國萬歲,萬萬歲"; /*宣告字串型態(變數)a預設值= */ String b = ""; /*字串b初始值是空的*/ int c = a.length(); /*方法 length() 得到字串長度*/ System.out.println("原來: " + a); System.out.println("長度: " + c); for (int i = 0; i wikipedia介紹VS Code功能 Visual Studio Code 預設支援非常多的 程式語言 ,包括 JavaScrip t、TypeScript、 CSS 和 HTML ;也可以透過下載擴充元件支援 Python 、C/C++、Java 和 Go 在內的其他語言[14]。支援功能包括語法突顯、括號補全、程式碼摺疊和程式碼片段;對於部分語言,可以使用 IntelliSense[15]。Visual Studio Code 也支援除錯 Node.js 程式。和 GitHub 的 Atom一樣,Visual Studio Code 也基於 Electron 框架構建[16]。 Visual Studio Code 支援同時打開多個目錄,並將資訊儲存在工作區中以便復用[17]。 作為跨平台的編輯器,Visual Studio Code 允許使用者更改檔案的頁碼、換行符號和程式語言。 EXCEL函數對應於Java length(),charAt()...

莊俊祥java遞迴函數Recursion function,遞迴Recursion

圖片
public class Main { //莊俊祥w3schools遞迴函數recursion public static void main(String[] args) { int x = 15; //宣告整數x for ( int i = 0; i 0) { //if-else條件判斷,語法同javascript return k + sum(k - 1); //recursion重複呼叫自己sum:遞迴 } else { //最有名的應用河內塔Hanoi Tower return 0; } } public static int factor(int k) {//自訂的方法,名稱factor if (k > 0) { //if-else條件判斷,語法同javascript return k * factor(k - 1); //recursion重複呼叫自己sum:遞迴 } else { //最有名的應用河內塔Hanoi Tower return 1; } } }

莊俊祥使用RStudio編輯表單input buttom text number輸出HTML

圖片
利用專業的整合開發環境R studio 常用的IDE整合法展環境有: 例如Microsoft發展的visual Studio code 例如Microsoft發展的visual Studio Code R Studio Atom Eclipse Intellisense JCreatork 表單輸入數字與呼叫JavaScript 輸出結果