2015FALL 40123210 CPB 作業

2015 計算機程式 作業七

以下為作業七內容

利用 iframe 嵌入投影片:

作業七投影片

Jupyter notebook 檔案內容:

In [1]:
print("*")
*
In [2]:
print("***")
***
In [3]:
print("*")
print(" *")
print("  *")
*
 *
  *
In [4]:
print("*"*5)
*****
In [5]:
for i in range(5):
    print(i)
0
1
2
3
4
In [6]:
for i in range(1, 5):
    print(i)
1
2
3
4
In [12]:
for i in range(1, 5):
    if i != 3:
         print(i)
1
2
4
In [13]:
for i in range(1, 5):
    if i %2 == 0:
        print(i)
2
4
In [14]:
for i in range(1, 5):
    if i > 3:
        print(i)
4
In [15]:
for i in range(1, 5):
    if i >3 or i <2 :
        print(i)
1
4
In [16]:
for i in range(1, 5):
    if i < 5 and i > 2:
        print(i)
3
4
In [17]:
for i in range(1, 5):
    print("*"*i)
*
**
***
****
In [18]:
for i in range(5, 0, -1):
    print("*"*i)
*****
****
***
**
*
In [19]:
for i in range(1, 5):
    print(" "*(i-1), end="")
    print("*")
*
 *
  *
   *
In [20]:
for i in range(5, 0, -1):
    print(" "*(i-1), end="")
    print("*")
    *
   *
  *
 *
*
In [21]:
for i in range(5):
    print((5-i-1)*" ", end="")
    print("*", end="")
    print((2*i-1)*" ",end="")
    if i != 0:
        print("*", end="")
    print((5-i-1)*" ", end="")
    print()
    *    
   * *   
  *   *  
 *     * 
*       *
In [22]:
for i in range(5-2, -1, -1):
    print((5-i-1)*" ", end="")
    print("*", end="")
    print((2*i-1)*" ",end="")
    if i != 0:
        print("*", end="")
    print((5-i-1)*" ", end="")
    print()
 *     * 
  *   *  
   * *   
    *    
In [23]:
for i in range(5):
    print((5-i-1)*" ", end="")
    print("*", end="")
    print((2*i-1)*" ",end="")
    if i != 0:
        print("*", end="")
    print((5-i-1)*" ", end="")
    print()
for i in range(5-2, -1, -1):
    print((5-i-1)*" ", end="")
    print("*", end="")
    print((2*i-1)*" ",end="")
    if i != 0:
        print("*", end="")
    print((5-i-1)*" ", end="")
    print()
    *    
   * *   
  *   *  
 *     * 
*       *
 *     * 
  *   *  
   * *   
    *    
In [24]:
def diamond(s):
    for i in range(5):
        print((5-i-1)*" ", end="")
        print("o", end="")
        print((2*i-1)*" ",end="")
        if i != 0:
            print("o", end="")
        print((5-i-1)*" ", end="")
        print()
    for i in range(5-2, -1, -1):
        print((5-i-1)*" ", end="")
        print("o", end="")
        print((2*i-1)*" ",end="")
        if i != 0:
            print("o", end="")
        print((5-i-1)*" ", end="")
        print()
diamond(10)
    o    
   o o   
  o   o  
 o     o 
o       o
 o     o 
  o   o  
   o o   
    o    
In [ ]:
 

w7_2015_11_10 from 40123210 on Vimeo.

Comments