# Python For Loop Assignment with solutions

Python For Loop Assignment is a collection of  FOR loop-based questions. Tutorial on for loop in python can help you to better understand it. This for loop assignment will check your understanding of iterative items as well as the most important function range( ).

Q1. Write the output of the following
a) for i in “python”:
print (i)
b) for i in range(5):
print(i)
c) for i in range(10,15):
print(i)
Q2. Write a program to print first 10 natural number
Solution

```for i in range(1,11):
print(i)
```

Q3. Write a program to print first 10 even numbers.
Solution

``` x=2
for i in range(10):
print(x)
x= x+2
```

Q4. Write a program to print first 10 odd numbers.
solution\

``` x=1
for i in range(10):
print(x)
x= x+2
```

Q5. Write a program to print first 10 even numbers in reverse order
solution

```list1=[]
x=2
for i in range(10)
list1.append(x)
x = x+2
print(list1[::-1])
```

Q6. Write a program to print table of a number accepted from user.

solution

```n = int(input('Enter any number :'))
for i in range(1,11):
print(n,'*',i,'=',n*i)
```

Q7. Write a program to find the factorial of a number
solution

```n = int(input('Enter any number :'))
fact=1
for i in range(1,n+1):
fact *=i
print(' Factorial of ',n ' is :',fact)
```

Q8. Write a program to check whether a number is prime or not.
solution:

```n = int(input('Enter any number :'))
found =0
for i in range(2,n//2+1):
if n%i==0:
found =1
if found==0:
print('Entered number is prime number ')
else:
print('Entered number is not a prime number')
```

Q9. Write a program in python to find out all the factors of an entered number.
solution
A factor is a number that is able to divide that number completely.

```n = int(input('Enter any number :'))
for i in range(2,n//2+1):
if n%i==0:
print(i, end=" ")
```

Q10. Write a python program to print the following pattern on the screen

```*
* *
* * *
* * * *
* * * * *
```

Solutions
Actually there are more than one soluton of the above problem.

```1st Solution

str1='*'
for i in range(1,6):
print(str1*i)

2nd solution

for i in range(1,6):
for j in range(1,i+1):
print('*',end= '')
print()```
`Q11. print the following pattern on the screen`
```                   1
1  2  1
1   2  3  2  1
1  2   3  4  3  2  1
1  2  3   4  5  4  3  2  1

```

Solution

```for  i in range(1,6):
for j in range(5-i):
print(' ', end=' ')    #print initial spaces
for k in range(1,i+1):
print(k, end=' ')
for l in range(i-1,0,-1):  # print number is in reverse order
print(l,end= ' ')
print()
```

These are only a few Python for loop assignment questions. If you like this Assignment, please share it with your friends.