---
# System prepended metadata

title: 訓練場_3程式繳交處
tags: [訓練場_st]

---

---
title: 訓練場_3程式繳交處
tags: 訓練場_st
---
> [訓練場_3 題目](https://hackmd.io/@futurenest/code_training_3)

> [程式線上編譯環境](https://replit.com/)
:::warning
繳交規範（可以複製這裡的喔）

`### 自己名字`
`#### 題目一` 
```python
程式碼
```
`#### 題目二` 
```c++
程式碼
```
:::
### 郭尚蓁

#### for loop
1. 答案
2. 答案
3. 答案
4. 答案
5. 答案

#### Range

1. 答案
2. 答案
3. 答案
4. 答案

```python
for i in range(5):
  sp = ''
  s = ''
  for j in range(i):
    sp += ' '
  for j in range(5-i):
    s += '*'
  print(sp+s)
```
> [format 格式參考](https://www.runoob.com/python/att-string-format.html) 

```python
n = int(input(""))

if 0 < n < 10:
  for i in range (1, 10):
    print("{} x {} = {}".format(n, i, n*i))
else:
  print("wrong")
```

```python
for i in range(1, 10):
  for j in range(1, 10):
    print("{} x {} = {}".format(i, j, i*j))
  print("")
```
```python
test = '1,2,3,4,5'
test_list = test.split(',')
print(test_list)
```
#### 判斷質數
```python
# while 迴圈寫法
n = int(input('輸入一個正整數:'))
i = 2

while i < n:
  if n % i == 0:
      print('不是質數')
      break
  i += 1

if i == n:
  print('是質數')
```

```python
# for 迴圈寫法
n = int(input('輸入一個正整數:'))

for i in range(2, n):
  if n % i == 0:
    print('不是質數')
    break    
  elif i == n-1:
    print('是質數')

if 2 == n:
  print('是質數')
```

```python
# 函數
def is_prime(number):
  for i in range(2, number):
    if number % i == 0:
      return False
  return True

n = int(input('輸入一個正整數:'))

if is_prime(n):
  print('是質數')
else:
  print('不是質數')
```

#### 回文數
```python
num = input("請輸入一個數:")

if num.isdigit():
  num = str(num)
  for i in range(len(num)):
    if num[i] == num[len(num)-i-1]:
      print(num, "是回文數")
    else:
      print(num, "不是回文數")
    break
else:
  print("請輸入自然數")
```

---









### 王政翔

#### for loop
```
1. 1
   2
   3
   
2. 2
   3
   4
   
3. hi
   hi
   hi

4. 2
   4
   6
   8

5. h
   e
   l
   l
   o
```
#### Range
```
1. 0
   1
   2
   3
   4
   
2. 1
   2
   3
   4
   
3. 1
   3
   5
   7
   9
   
4. 10
   9
   8
   7
   6
   5
   4
   3
   2
   1
   0
```
#### 練習
```python=
#1
for i in range(1,50):
    print(i)
#2
for i in range(1,11):
    print(i**2)
#3
for i in range(0,5):
    print('*' * (i+1))
#4
0
#5
num = int(input("輸入n = "))
for i in range(1,10):
  print(num*i)
#6
num = int(input("輸入n = "))
if 1 <= num <= 9: 
  for i in range(1,10):
    print(num, ' x ', i, ' = ', (num * i))
else:
  print('wrong')
#7
for i in range(1,10):
  for j in range(1,10):
    print(i, ' x ', j, ' = ', (i * j))
  print('\n')
```

### 張云綺
#### for loop
1.   1 2 3
2.   2 3 4
3.   hi hi hi
4.   2 4 6 8
5.   h e l l o

#### Range

1.   0 1 2 3 4 
2.   1 2 3 4 
3.   1 3 5 7 9 
4.   10 9 8 7 6 5 4 3 2 1 0
#### 練習題 
``` python
1.for i in range(1,50,1):
  print(i)

2.for i in range(11):
  print(i ** 2)

3.for i in range(1,6):
    print('*' * i)

4.num = int(input('請輸入1到9的數字'))
if 0<num<10 :
   for i in range (1,10):
    print('{}x{} = {}' . format(num,i,num*i) )

5.number = int(input('請輸入1到9的數字'))

for i in range (1,10):
  print( number*i )

6.num = int(input('請輸入1到9的數字'))
if 0<num<10 :
   for i in range (1,10):
    print('{}x{} = {}' . format(num,i,num*i) )
   
else:
      print('not true')

7.for i in range(1,10):
  for u in range(1,10):
    print('{}x{} = {}' . format(i,u,i*u) )
  print('')

```

### 林永晉
#### for loop
```
1. 1
   2
   3
   
2. 2
   3
   4
   
3. hi
   hi
   hi
   
4. 2
   4
   6
   8
   
5. h
   e
   l
   l
   o
```
#### Range
```
1. 0
   1
   2
   3
   4
   
2. 1
   2
   3
   4
   
3. 1
   3
   5
   7
   9
   
4. 10
   9
   8
   7
   6
   5
   4
   3
   2
   1
   0
```
#### 練習1
```python=
for i in range(1,50):
    print(i)
```
#### 練習2
```python=
for i in range(1,11):
    print(i ** 2)
```
#### 練習3
```python=
for i in range(1,6):
    print('*' * i)
```
#### 練習4
```python=
for i in range(1,6):
    for j in range(1,6):
        if j<i:
            print(' ',end='')
        else:
            print('*',end='')
    print()
```
#### 練習5
```python=
n = eval(input('enter a number:'))
for i in range(1,10):
    print(i * n)
```
#### 練習6
```python=
def cal(n):
    if n in(1,2,3,4,5,6,7,8,9):
        for i in range(1,10):
            print('%d x'%(n),i,'=',n * i)
    else:
        print('wrong')

cal(eval(input('enter a number:')))
```
#### 練習7
```python=
for i in range(1,10):
    for j in range(1,10):
        print('%d x %d = %d'%(i,j,j * i))
    print()
```


### 楊芷瑜
#### for loop
```
1. 1 2 3
2. 2 3 4
3. hi hi hi
4. 2 4 6 8 
5. h e l l o 
```
#### Range
```
1.0 1 2 3 4 
2.1 2 3 4 
3.1 3 5 7 9 
4. 10 9 8 7 6 5 4 3 2 1 
```

#### 練習
```python=
1.for i in range(1, 50):
    print(i)
```
```python=
2.for i in range(1,11):
    print(i**2)
```
```python=
3.for i in range(1,6):
    print("*"*i)
```
```python=
4.for i in range(5,0,-1):
    print("*"*i)
```
```python=
5.n=int(input("輸入數字"))
for i in range(1,10):
    print(i*n)
```
```python=
6.n=int(input("輸入數字"))

if 0 < n < 10:
 for i in range (1,10):
   print("{}x{}= {}".format(n,i,n*i))
else:
  print("wrong")
  ```
```python=
7.for i in range(1,10):
    for k in range(1,10):
    print("{}x{}={}".format(i,k,i*k))
  print("")
```
```

```
### 張若聞
#### for loop
```
1. 1 2 3
2. 2 3 4
3. hi hi hi
4. 2 4 6 8
5. h e l l o
```
#### Range
```
1. 0 1 2 3 4
2. 1 2 3 4
3. 1 3 5 7 9
4. 10 9 8 7 6 5 4 3 2 1 
```
#### 練習 1
```c++=
#include <iostream>
using namespace std;

int main(){

  for(int i = 1; i < 50; i++)
    cout << i << endl;
 
  return 0;
}
```
#### 練習 2
```c++=
#include <iostream>
using namespace std;

int main(){

  for(int i = 1; i <= 10; i++)
    cout << i * i << endl;
 
  return 0;
}
```
#### 練習 3
```c++=
#include <iostream>
using namespace std;

int main(){
    int i, j;
    cin >> i, j;
    
    for (i = 0; i < 5; i++) {
        for (j = 0; j <= i; j++)
            cout << "*";
        cout << endl;
    }
  
  return 0;
}
```
#### 練習 4
```c++=
#include <iostream>
using namespace std;

int main(){
    int i, j;
    cin >> i, j;
    
    for (i = 0; i < 5; i++) {
        for (j = 4; j >= i; j--)
            cout << "*";
        cout << endl;
    }
  
  return 0;
}
```
#### 練習 5
```c++=
#include <iostream>
using namespace std;

int main(){
    int n;
    cin >> n;
    
    for (int i = 1; i <= 9; i++) {
      cout << n * i << "\t" ;
      cout << endl;
    }
  
  return 0;
}
```
#### 練習 6
```c++=
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    
    if (n < 1 || n > 9)
      cout << "wrong"; 
    else
      for (int i = 1; i <= 9; i++) {
        cout << n << " * " << i << " = " << i * n << "\t" ;
        cout << endl;
    }
  
  return 0;
}
```
#### 練習 7
```c++=
#include <iostream>
using namespace std;

int main() {
    
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++){
            cout << i << " * " << j << " = " << i * j << endl;
        }
        cout << endl;
    }
  
  return 0;
}
```
### 楊苡若
#### for loop
1.
```python=
1
2
3
```
2.
```python=  
2
3
4
```
3.
```python=
hi
hi
hi
```
4.
```python=
2
4
6
8
```
5.
```python=
h
e
l
l
o
```
#### Range
1.
```python=
0
1
2
3
4
```
2.
```python=
1
2
3
4
```
3.
```python=
1
3
5
7
9
```
4.
```python=
10
9
8
7
6
5
4
3
2
1
0
```
#### 練習
1.
```python=
for i in range(1, 50):
    print(i)
```
2.
```python=
for i in range(1, 10):
  print(i ** 2)
```
3.
```python=
for i in range(1, 6):
    print('*' * i)

```
4.
```python=
for i in range(5, 0, -1):
    print('*' * i)

```
5.
```python=
number = int(input(''))

if 10 > number > 0:
  for i in range(1, 10):
    print('{} x {} = {}'.format(number, i, number * i))
else:
  print('錯誤') 

```
6.
```python=
for i in range(1, 10):
  for j in range(1, 10):
    print('{} x {} = {}'.format(i, j, i*j))
  print('')
```
7.
```python=

```
### Josh
```python=
for i in range(5, 0, -1):
  for k in range(0, 5-i):
    print(' ', end = '')
  for j in range(0, i):
    print('*', end = '')
  print('') 
```