Tuesday, 13 February 2024

Class 11 CS Practical - 23

 

23 - Write a program in Python to print all Armstrong numbers from 0 to 10000.


for n in range(0,10001):

    sum=0

    k=n

    while n>0:

        r=n%10

        n=n//10

        sum=sum+r*r*r

 

    if(sum==k):

        print(k,end=" ")


Output:

0 1 153 370 371 407 

Class 11 CS Practical - 22

 

22 - Write a program in Python to input a number and determine whether the number is an Armstrong number or not.


n=int(input("Enter a number: "))

sum=0

k=n

while n>0:

    r=n%10

    n=n//10

    sum=sum+r*r*r

 

if(sum==k):

    print(k, "is a armstrong number")

else:

    print(k, "is not a armstrong number")


Output:

Enter a number: 153
153 is a armstrong number

Enter a number: 147
147 is not a armstrong number



Class 11 CS Practical - 21

 

21 - Write a program in Python to input a number and determine the multiplication of the digits of that number.

n=int(input("Enter a number: "))

product=1

while n>0:

    r=n%10

    n=n//10

    product=product*r

print("Multiplication of digits=",product)


Output:

Enter a number: 145
Multiplication of digits= 20

Enter a number: 346
Multiplication of digits= 72

Class 11 CS Practical - 20

 

20 - Write a program in Python to input a number and determine the sum of the digits of that number.


n=int(input("Enter a number: "))

sum=0

while n>0:

    r=n%10

    n=n//10

    sum=sum+r

print("Sum of digits=",sum)


Output:

Enter a number: 145
Sum of digits= 10

Enter a number: 346
Sum of digits= 13

Class 11 CS Practical - 19

 

19 - Write a program in Python to display the first 'n' terms of a Fibonacci series. 


a=0

b=1

n=int(input("Enter the number of terms to be printed for fibonacci Series: "))

print(a, b,end=' ')

for i in range(1,n-1):

    c=a+b

    print(c,end=' ')

    a=b

    b=c


Output:

Enter the number of terms to be printed for fibonacci Series: 10

0 1 1 2 3 5 8 13 21 34 

Tuesday, 6 February 2024

Class 11 CS Practical - 18

 

18 - Write a program in Python to generate the following pattern using nested loops:

     1

   234

  56789

 10111213141516


p=1

a=5

k=2

n=3

for i in range(1,5):

    for s in range(1,a):

        print(end=' ')

    for j in range(p,k):

        print(j,end='')

    print()

    a=a-1

    p=j+1

    k=k+n

    n=n+2

   

Output:

     1

   234

  56789

 10111213141516


Class 11 CS Practical - 17

 

17 - Write a program in Python to generate the following pattern using nested loops:

ABCDEFEDCBA

ABCDE EDCBA

ABCD      DCBA

ABC            CBA

AB                 BA

A                       A


y=71

sp=2

for i in range(1,8):

    x=65

   

    while(x<y):

        print(chr(x),end='')

        x=x+1

    if i==1:

        x=x-2

    else:

        x=x-1

        for s in range(1,sp):

            print(end=' ')

        sp=sp+2   

    while(x>64):

        print(chr(x),end='')

        x=x-1

    print()

    y=y-1

   

Output:

ABCDEFEDCBA

ABCDE EDCBA

ABCD      DCBA

ABC            CBA

AB                 BA

A                       A


Class 11 CS Practical - 16

 

16 - Write a program in Python to generate the following pattern using nested loops:

     1

   123

  12345

 1234567

123456789


sp=5

k=2

for i in range(1,6):

    for s in range(1,sp):

        print(end=' ')

    for j in range(1,k):

        print(j,end='')

    print()

    sp=sp-1

    k=k+2


 Output:

     1

   123

  12345

 1234567

123456789

Class 11 CS Practical - 15

 

15 - Write a program in Python to generate the following pattern using nested loops:

*

**

***

****

*****


for i in range(1,6):

    for j in range(1,i+1):

        print("*",end='')

    print()

 

Output:

*

**

***

****

*****


Class 11 CS Practical - 14

 

14 - Write a program in Python to generate the following pattern using nested loops:

A

AB

ABC

ABCD

ABCDE


for i in range(1,6):

    for j in range(1,i+1):

        print(chr(j+64),end='')

    print()


Output:

A

AB

ABC

ABCD

ABCDE