# For loop 

- To iterate over the List. 

- for **int** in range():

- range(end no)
- range(start no.,end no.)
- range(start no.,end no.,step)


```python
d=[1,2,3,4,5]
```


```python
d.append(108)
d
```




    [1, 2, 3, 4, 5, 108]




```python
L = []
for i in range (10):
    L.append(i)
L
```




    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]




```python
L = []
for i in range(20):
    L.append(i)
L
```




    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]




```python
a = []
for k in range(2,10):
    a.append(k)
a
```




    [2, 3, 4, 5, 6, 7, 8, 9]




```python
b = []
for i in range(2,21,2):
    b.append(i)
b
```




    [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]




```python
sum(b)
```




    110




```python
a+b
```




    [2, 3, 4, 5, 6, 7, 8, 9, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]




```python
sum(a+b)
```




    154




```python
D = []
for i in range(1,5):
    for j in range(1,5):
        D.append(i+2*j) 
        print(D)
```

    [3]
    [3, 5]
    [3, 5, 7]
    [3, 5, 7, 9]
    [3, 5, 7, 9, 4]
    [3, 5, 7, 9, 4, 6]
    [3, 5, 7, 9, 4, 6, 8]
    [3, 5, 7, 9, 4, 6, 8, 10]
    [3, 5, 7, 9, 4, 6, 8, 10, 5]
    [3, 5, 7, 9, 4, 6, 8, 10, 5, 7]
    [3, 5, 7, 9, 4, 6, 8, 10, 5, 7, 9]
    [3, 5, 7, 9, 4, 6, 8, 10, 5, 7, 9, 11]
    [3, 5, 7, 9, 4, 6, 8, 10, 5, 7, 9, 11, 6]
    [3, 5, 7, 9, 4, 6, 8, 10, 5, 7, 9, 11, 6, 8]
    [3, 5, 7, 9, 4, 6, 8, 10, 5, 7, 9, 11, 6, 8, 10]
    [3, 5, 7, 9, 4, 6, 8, 10, 5, 7, 9, 11, 6, 8, 10, 12]



```python
D = []
for i in range(1,5):
    print(D)
    for j in range(1,5):
        D.append(i+2*j) 
```

    []
    [3, 5, 7, 9]
    [3, 5, 7, 9, 4, 6, 8, 10]
    [3, 5, 7, 9, 4, 6, 8, 10, 5, 7, 9, 11]



```python
D = []
for i in range(1,5):
    for j in range(1,5):
        D.append(i+2*j) 
D        
```




    [3, 5, 7, 9, 4, 6, 8, 10, 5, 7, 9, 11, 6, 8, 10, 12]




```python
p = [] # empty list l
for i in range(1,5):
    for j in range(1,5):
        p.append(i+2*j) 
        print('í=',i,'j=',j,'p=',p)
```

    í= 1 j= 1 p= [3]
    í= 1 j= 2 p= [3, 5]
    í= 1 j= 3 p= [3, 5, 7]
    í= 1 j= 4 p= [3, 5, 7, 9]
    í= 2 j= 1 p= [3, 5, 7, 9, 4]
    í= 2 j= 2 p= [3, 5, 7, 9, 4, 6]
    í= 2 j= 3 p= [3, 5, 7, 9, 4, 6, 8]
    í= 2 j= 4 p= [3, 5, 7, 9, 4, 6, 8, 10]
    í= 3 j= 1 p= [3, 5, 7, 9, 4, 6, 8, 10, 5]
    í= 3 j= 2 p= [3, 5, 7, 9, 4, 6, 8, 10, 5, 7]
    í= 3 j= 3 p= [3, 5, 7, 9, 4, 6, 8, 10, 5, 7, 9]
    í= 3 j= 4 p= [3, 5, 7, 9, 4, 6, 8, 10, 5, 7, 9, 11]
    í= 4 j= 1 p= [3, 5, 7, 9, 4, 6, 8, 10, 5, 7, 9, 11, 6]
    í= 4 j= 2 p= [3, 5, 7, 9, 4, 6, 8, 10, 5, 7, 9, 11, 6, 8]
    í= 4 j= 3 p= [3, 5, 7, 9, 4, 6, 8, 10, 5, 7, 9, 11, 6, 8, 10]
    í= 4 j= 4 p= [3, 5, 7, 9, 4, 6, 8, 10, 5, 7, 9, 11, 6, 8, 10, 12]



```python
A = [10*k for k in range(10)]
print(A)
```

    [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]



```python
AA = [[10*x+y for x in range(4)] for y in range(3)]
print(AA)
```

    [[0, 10, 20, 30], [1, 11, 21, 31], [2, 12, 22, 32]]



```python
summ = 0
for i in range(1,11):
    summ = summ+i
print(summ)
```

    55



```python
product = 1
for i in range(1,11):
    product = product*i
    print(product)
```

    1
    2
    6
    24
    120
    720
    5040
    40320
    362880
    3628800


### Projectile
- Range
\begin{equation}
R=\frac{u^2\sin2\theta}{2g}
\end{equation}
- Max.Height
\begin{equation}
H=\frac{u^2\sin^2\theta}{2g}
\end{equation}

- using list


```python
import numpy as np
u=100
g=9.8
angle=[]
Range=[]
PI=np.pi
for i in range(0,90):
    angle.append(i)
    Range.append(u**2*np.sin(2*PI*i/180)/(2*g))    
```

- import matplotlib.pyplot as plt
- %matplotlib inline
- plt.plot(x,y)


```python
import matplotlib.pyplot as plt
%matplotlib inline
plt.plot(angle,Range)
plt.xlabel('Angle')
plt.ylabel('Range')
plt.title('Projectile')
```

- using dictionary


```python
angle = np.arange(1,90)
M = {"Range": [u**2*np.sin(2*PI*x/180)/(2*g) for x in angle],\
     "Max.height": [u**2*np.sin(PI*x/180)**2/(2*g) for x in angle]}
```


```python
import pandas as pd
DF = pd.DataFrame(M)
DF
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Range</th>
      <th>Max.height</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>17.805866</td>
      <td>0.155401</td>
    </tr>
    <tr>
      <th>1</th>
      <td>35.590038</td>
      <td>0.621416</td>
    </tr>
    <tr>
      <th>2</th>
      <td>53.330849</td>
      <td>1.397476</td>
    </tr>
    <tr>
      <th>3</th>
      <td>71.006684</td>
      <td>2.482636</td>
    </tr>
    <tr>
      <th>4</th>
      <td>88.596009</td>
      <td>3.875573</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>84</th>
      <td>88.596009</td>
      <td>506.328508</td>
    </tr>
    <tr>
      <th>85</th>
      <td>71.006684</td>
      <td>507.721446</td>
    </tr>
    <tr>
      <th>86</th>
      <td>53.330849</td>
      <td>508.806606</td>
    </tr>
    <tr>
      <th>87</th>
      <td>35.590038</td>
      <td>509.582666</td>
    </tr>
    <tr>
      <th>88</th>
      <td>17.805866</td>
      <td>510.048680</td>
    </tr>
  </tbody>
</table>
<p>89 rows × 2 columns</p>
</div>




```python
DF.plot()
plt.xlabel('Angle(degree)')
plt.ylabel('Distance(m)')
plt.title('Projectile')
```


```python

```

3e109de520f16e6512e2c7278ccf9d272c3d3d05
ipynb
Jupyter Notebook
forloop.ipynb
aausha/NPS
507897b385ba8f89134b31d8e80ed46d7bc0fe7d
MIT
forloop.ipynb
aausha/NPS
507897b385ba8f89134b31d8e80ed46d7bc0fe7d
MIT
forloop.ipynb
aausha/NPS
507897b385ba8f89134b31d8e80ed46d7bc0fe7d
MIT
Qwen/Qwen-72B
1. YES
2. YES

