<style> .hiddenDiv { color: white; } </style> 程式設計(ㄧ) - 基礎題庫(6) === :::info 這次題庫不小心會影分身之術, 多了幾個小題 ::: ## 第一小題 ### Input 輸入一串文字 ### Output 把文字拆開印出 <div class="hiddenDiv"> 1. 字串可以當作 for 迴圈的對象, 每次只會拿一個字出來 </div> <div class="hiddenDiv"> 2. 也可以用 len() 取得字串長度, 在一個一個顯示 </div> <div class="hiddenDiv"> for 單字 in 某個字串: print(單字) </div> ### 範例 #### 輸入 ```shell= my name is old fish ``` #### 輸出 ```shell= m y n a m e i s o l d f i s h ``` ## 第二小題 ### Input 輸入一串數字 ### Output 把數字全部加總 <div class="hiddenDiv"> 1. 讀入時是字串, 可以參考第一小題的做法 </div> <div class="hiddenDiv"> 2. 每次計算時候再換成數字來加總 </div> ### 範例 #### 輸入 ```shell= 5487945 ``` #### 輸出 ```shell= 42 ``` ## 第三小題 ### Input 輸入一個數字 ### Output 判斷是不是質數 <div class="hiddenDiv"> 1. 參考以前上課的檔案 </div> <div class="hiddenDiv"> 2. 輸入 n, 只要不能被 2 ~ n-1 整除就是質數 </div> ### 範例 #### 輸入 ```shell= 3 ``` #### 輸出 ```shell= YES ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up