Python Loop Questions
Python Loop Questions
```python
for num in range(1, 21):
if num % 2 == 0:
print(num, end=" ")
```
**Output:**
```
2 4 6 8 10 12 14 16 18 20
```
```python
N = int(input("Enter a number: "))
sum_n = 0
i=1
while i <= N:
sum_n += i
i += 1
```python
num = int(input("Enter a number: "))
reverse = 0
```python
num = int(input("Enter a number: "))
count = 0
```python
rows = 5
```python
for num in range(10, 51):
is_prime = True
for i in range(2, num):
if num % i == 0:
is_prime = False
break
if is_prime:
print(num, end=" ")
```
**Output:**
```
11 13 17 19 23 29 31 37 41 43 47
```
9. Sum of Digits using While Loop
Write a Python program that finds the sum of digits of a given number using a while loop.
```python
num = int(input("Enter a number: "))
sum_digits = 0
```python
N = int(input("Enter the number of terms: "))
a, b = 0, 1
for _ in range(N):
print(a, end=" ")
a, b = b, a + b
```
**Example Input:**
```
Enter the number of terms: 7
```
**Output:**
```
0112358
```