Python Assignment
1) Write a program to print matrix of -
Output:
1 1 1
1 1 1
Python Code:
for i in range(2):
for j in range(3):
print(1,end=" ")
print()
2) WAP to print matrix of -
Output:
1234
1234
1234
Python Code:
for i in range(3):
for j in range(1,5):
print(j,end="")
print()
3) WAP to print matrix of -
Output:
1111
2222
3333
Python Code:
for i in range(1,4):
for j in range(4):
print(i,end="")
print()
4) WAP to print diagonal matrix of 0 and 1.
Output:
1000
0100
0010
0001
Python Code:
n=4
for i in range(n):
for j in range(n):
if i==j:
print(1,end="")
else:
print(0,end="")
print()
5) WAP to print matrix of 1's in which number of rows and columns is input
by user.
Output:
Example if r=3 c=4:
1 1 1 1
1 1 1 1
1 1 1 1
Python Code:
r=int(input())
c=int(input())
for i in range(r):
for j in range(c):
print(1,end=" ")
print()
6) WAP to print -
Output:
1
11
111
1111
Python Code:
for i in range(1,5):
for j in range(i):
print(1,end="")
print()
7) WAP to print triangle -
Output:
55555
4444
333
22
1
Python Code:
for i in range(5,0,-1):
for s in range(5-i):
print(" ",end="")
for j in range(i):
print(i,end="")
print()
8) WAP to print even number series starting from 20 upto 30 (inclusive) using
while statement.
Output:
20 22 24 26 28 30
Python Code:
i=20
while i<=30:
if i%2==0:
print(i,end=" ")
i+=1
9) WAP to generate series in which starting number is given by user upto
next 20 numbers.
Output:
Example if input=10:
11 12 13 ... 30
Python Code:
n=int(input())
for i in range(n+1,n+21):
print(i,end=" ")
10) WAP to print series of number given by user depending upon even or
odd number (length 10).
Output:
Example if input=10:
10 12 14 16 18 20 22 24 26 28
Python Code:
n=int(input())
count=0
i=n
while count<10:
if n%2==0:
if i%2==0:
print(i,end=" ")
count+=1
else:
if i%2!=0:
print(i,end=" ")
count+=1
i+=1