Tuesday, 13 February 2024

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


Class 11 CS Practical - 13

 

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

5

54

543

5432

54321


for i in range(5,0,-1):

    for j in range(5,i-1,-1):

        print(j,end='')

    print()


Output:

5

54

543

5432

54321


Class 11 CS Practical - 12

 

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

54321

5432

543

54

5


for i in range(1,6):

    for j in range(5,i-1,-1):

        print(j,end='')

    print()


Output:

54321

5432

543

54

5


Class 11 CS Practical - 11

 

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

55555

4444

333

22

1


for i in range(5,0,-1):

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

        print(i,end='')

    print()

 

Output:

55555

4444

333

22

1