ECE054-Lab1
ECE054-Lab1
ipynb - Colaboratory
1) Write a program to check whether a number is strong number or not.Strong number is a special number whose sum of factorial of digits is
equal to the original number. For example: 145 is strong number. Since, 1! + 4! + 5! = 145
sum=0
a=int(input("Enter a number: "))
temp=a
while(a):
i=1
factorial=1
rem=a%10
while(i<=rem):
factorial=factorial*i
i=i+1
sum=sum+factorial
a=a//10
if(sum==temp):
print("Given number is a strong number")
else:
print("Given number is not a strong number")
2) Write a Python program that calculates and prints the sum of squares of all possible pairs of two distinct integers from a given range
[start, end] including start and end values.
Starting Point: 1
Ending Point: 4
30
3) The Fibonacci series numbers are given as: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, . . . In a Fibonacci series, every term is the sum of the preceding
two terms, starting from 0 and 1 as the first and second terms. Write a python program to print Fibonacci series in a given range [ start, end]
including start and end values.
Number Of Elements: 5
[0, 1, 1, 2, 3, 5, 8]
4) In the below code snippet try changing the value of x from 1 to 5 and run code each time.
x=10
for j in range(1,x+1):
print(j, end=' ')
print(' ')
print("over")
1 2 3 4 5 6 7 8 9 10
over
5) Modify the above code to print the pattern as below. Take as input no: of rows
https://colab.research.google.com/drive/1Er27FFzgyaj9L2SgR9drVkc1Xyh_zEqP?usp=drive_open#printMode=true 1/5
09/12/2023, 21:36 ECE054-Lab5.ipynb - Colaboratory
#(i)
a=int(input("Number Of Rows: "))
for i in range(1,a+1):
for j in range(1,i+1):
print(i,end=" ")
print()
Number Of Rows: 6
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
#(ii)
a=int(input("Number Of Rows: "))
for i in range (1,a+1):
for j in range (1,i+1):
print(j,end=" ")
print()
Number Of Rows: 5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
6. Explain how the below code works. Try changing the value of k
k=6
i=6
print("start")
for j in range(1, k+1):
print(end=" ")
k = k-1
for j in range(1, i + 1):
print("*", end="")
print("")
print('Over')
start
******
Over
7) Write python program to print the below patterns. Take as input no: of rows
#(a)
a=int(input("Enter The Height: "))
for i in range(n):
for j in range(i, n):
print(' ', end=' ')
for j in range(i+1):
print('*', end=' ')
print()
#(b)
n=int(input("Number Of Rows: "))
for i in range(n):
for j in range(i+1):
print(' ', end=' ')
for j in range(i, n):
print('*', end=' ')
print()
Number Of Rows: 5
* * * * *
* * * *
* * *
* *
*
https://colab.research.google.com/drive/1Er27FFzgyaj9L2SgR9drVkc1Xyh_zEqP?usp=drive_open#printMode=true 2/5
09/12/2023, 21:36 ECE054-Lab5.ipynb - Colaboratory
#(c)
n=int(input("Number Of Rows: "))
k = 2*n-2
for i in range(n, -1, -1):
for j in range(k, 0, -1):
print(end=" ")
k = k + 1
for j in range(0, i + 1):
print("*", end=" ")
print("")
Number Of Rows: 5
* * * * * *
* * * * *
* * * *
* * *
* *
*
#(d)
n=int(input("Number Of Rows: "))
for i in range(1, n + 1):
print("*"*i," "*(2*n-2*i)+"*"*i)
Number Of Rows: 5
* *
** **
*** ***
**** ****
***** *****
#(e)
n=int(input("Number Of Rows: "))
for i in range(n-1):
for j in range(i):
print(' ', end='')
for k in range(2*(n-i)-1):
print('*', end='')
print()
for i in range(n):
for j in range(n-i-1):
print(' ', end='')
for k in range(2*i+1):
print('*', end='')
print()
Number Of Rows: 6
***********
*********
*******
*****
***
*
***
*****
*******
*********
***********
#(a)
a=int(input("Number Of Rows: "))
for i in range(1,a+1):
for j in range(1,i+1):
print(j,end="")
print()
Number Of Rows: 5
1
12
123
1234
12345
https://colab.research.google.com/drive/1Er27FFzgyaj9L2SgR9drVkc1Xyh_zEqP?usp=drive_open#printMode=true 3/5
09/12/2023, 21:36 ECE054-Lab5.ipynb - Colaboratory
#(b)
a=int(input("Number Of Rows: "))
for i in range(1,a+1):
num=1
for j in range(a,0,-1):
if j>i:
print(" ", end="")
else:
print(num, end="")
num +=1
print()
Number Of Rows: 5
1
12
123
1234
12345
#(c)
n=int(input("Enter Number Of Rows: "))
for i in range(1,n+1):
print(" " * (n-i), end="")
for j in range(1, i + 1):
print(j, end="")
for j in range(i, 0, -1):
print(j, end="")
print()
#(d)
n=int(input("Number Of Rows: "))
for i in range(n,0,-1):
for j in range(1, i + 1):
print(j, end="")
print()
Number Of Rows: 5
12345
1234
123
12
1
#(e)
rows = int(input("Enter Number Of Rows: "))
for i in range(0, rows + 1):
print(" " * (rows - i), end="")
for j in range(1, i + 1):
print(j, end="")
for j in range(i+1, 0, -1):
print(j, end="")
print()
https://colab.research.google.com/drive/1Er27FFzgyaj9L2SgR9drVkc1Xyh_zEqP?usp=drive_open#printMode=true 4/5
09/12/2023, 21:36 ECE054-Lab5.ipynb - Colaboratory
#(f)
n = int(input("Enter the number of rows: "))
for i in range(1, n + 1):
print(" " * (n - i), end="")
https://colab.research.google.com/drive/1Er27FFzgyaj9L2SgR9drVkc1Xyh_zEqP?usp=drive_open#printMode=true 5/5