ชื่อ ทดสอบ รหัส 60


In [1]:
x = [1,2,3]
y = (1,2,3)

In [2]:
type(x)


Out[2]:
list

In [3]:
type(y)


Out[3]:
tuple

In [4]:
x[0] = 5

In [5]:
print(x)


[5, 2, 3]

In [6]:
print(x[1:3])


[2, 3]

In [7]:
import math as m

In [8]:
m.log(10)


Out[8]:
2.302585092994046

In [9]:
m.log2(4)


Out[9]:
2.0

In [10]:
m.log(4,2)


Out[10]:
2.0

In [11]:
import numpy as np
Z = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])

In [12]:
Z[1,:]


Out[12]:
array([5, 6, 7, 8])

In [13]:
Z[:,1:2]


Out[13]:
array([[ 2],
       [ 6],
       [10]])

In [14]:
Z[0:2,1:3]


Out[14]:
array([[2, 3],
       [6, 7]])

In [15]:
from time import sleep
from math import sin, cos, radians

# increase 40 to get more wave
for n in range(1, 40):
    circle_1 = 50 * (1 + sin(radians(n*10)))
    circle_2 = 50 * (1 + cos(radians(n*10)))
    print("#".center(int(circle_1)))
    print("*".center(int(circle_2)))
    sleep(0.05)


                            #                             
                                                 *                                                 
                                 #                                 
                                               *                                                
                                     #                                     
                                              *                                              
                                        #                                         
                                           *                                            
                                           #                                            
                                        *                                         
                                              #                                              
                                     *                                     
                                               #                                                
                                 *                                 
                                                 #                                                 
                            *                             
                                                 #                                                  
                        *                         
                                                 #                                                 
                    *                    
                                               #                                                
               *                
                                              #                                              
            *            
                                           #                                            
        *        
                                        #                                         
     *     
                                     #                                     
  *   
                                 #                                 
 * 
                            #                             
*
                        #                         
*
                    #                    
*
               #                
 * 
           #            
  *   
        #        
     *     
     #     
        *        
  #   
           *            
 # 
               *                
#
                    *                    
#
                        *                        
#
                            *                             
 # 
                                 *                                 
  #   
                                     *                                     
     #     
                                        *                                         
        #        
                                           *                                            
           #            
                                              *                                              
               #                
                                               *                                                
                    #                    
                                                 *                                                 
                        #                        
                                                 *                                                  
                            #                             
                                                 *                                                 
                                 #                                 
                                               *                                                
                                     #                                     
                                              *                                              

In [16]:
import numpy as np
x = np.array([1+2j,3+4j])
print("First array:")
print(x)
y = np.array([5+6j,7+8j])
print("Second array:")
print(y)
z = np.vdot(x, y)
print("Product of above two arrays:")
print(z)


First array:
[ 1.+2.j  3.+4.j]
Second array:
[ 5.+6.j  7.+8.j]
Product of above two arrays:
(70-8j)

In [17]:
import numpy as np
x = np.array([1+2j,3+4j])
print("First array:")
print(x)
y = np.array([5+6j,7+8j])
print("Second array:")
print(y)
z = np.dot(x, y)
print("Product of above two arrays:")
print(z)


First array:
[ 1.+2.j  3.+4.j]
Second array:
[ 5.+6.j  7.+8.j]
Product of above two arrays:
(-18+68j)

In [18]:
import numpy as np
x = np.array([1+2j,3+4j])
print("First array:")
print(x)
y = np.array([5+6j,7+8j])
print("Second array:")
print(y)
z = np.cross(x, y)
print("Product of above two arrays:")
print(z)


First array:
[ 1.+2.j  3.+4.j]
Second array:
[ 5.+6.j  7.+8.j]
Product of above two arrays:
-16j

In [19]:
def sum_div(number):
    divisors = [1]
    for i in range(2, number):
        if (number % i)==0:
            divisors.append(i)
    return divisors
print(sum_div(12))


[1, 2, 3, 4, 6]

In [20]:
from math import radians, sin, cos, acos

print("Input coordinates of two points:")
slat = radians(float(input("Starting latitude: ")))
slon = radians(float(input("Ending longitude: ")))
elat = radians(float(input("Starting latitude: ")))
elon = radians(float(input("Ending longitude: ")))

dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon))
print("The distance is %.2fkm." % dist)


Input coordinates of two points:
Starting latitude: 18.245869
Ending longitude: 99.02548
Starting latitude: 18.452223
Ending longitude: 99.14257
The distance is 26.06km.

In [21]:
x = [1,2,[3,4,5],'xyz']

In [22]:
print(x[-len(x)])


1

In [23]:
len(x)


Out[23]:
4

In [24]:
x


Out[24]:
[1, 2, [3, 4, 5], 'xyz']

In [25]:
print(x[-4])


1

In [ ]: