Skip to main content

Posts

Showing posts from February, 2022

Computer Science | Class 11 CBSE | 2021-22 Session

CS Important Question  Q. Write a program to find palindrome of a given number. Answer → Logic: Number given=158 palindrome=158+851=1009                     1009+9001=10010                     10010+01001=110011 Code: n=int(input('Enter any number:')) while True:     sn=str(n)     rev=sn[::-1]     if sn==rev:         print(n,'is palindrome')         break     else:         n=int(sn)+int(rev)

Computer Science Practical File Question | Class 11 CBSE | 2021-22 Session|

CS Practical File Question   Q. Write a program to display first n prime numbers. Answer → n=int(input('Enter the number of prime numbers needed:')) j=2 while n!=0:     for i in range(2,j):         if j%i==0:             break     else:         print(j,end=' ')         n=n-1     j=j+1

Computer Science Practical File Question | Class 11 CBSE | 2021-22 Session|

CS Practical File Question Q. Generate the following pattern using nested loop.       *       * *       * * *       * * * *       * * * * *  Ans. for i in range(1,6):           #outer loop              for j in range(1,i+1):        #inner loop                  print('*',end=' ')              print() Q. Generate the following pattern using nested loop.        A         A B        A B C         A B C D        A B C D E Ans. for i in range(1,6):        #outer loop     for j in range(1,i+1):      #inner loop         if j==1:             j='A'         elif j==2:             j='B'         elif j==3:             j='C'         elif j==4:             j='D'         else: