Class 11 CBSE Computer Science General Practical
Class 11 CBSE Computer Science General Practical
print("Hello, ",message)
Hello, hii
Q2. # Python Program to input 2 numbers and display larger number
if (num1>num2):
else:
Output :
if (num1<num2):
else:
Output :
1. for i in range(1,10):
for j in range(i):
print('*',end='')
print('')
Output :
**
***
****
*****
******
*******
********
*********
2. #Number Pattern
for i in range(5,0,-1):
for j in range(1,i+1):
print(j,end="")
print()
Output :
12345
1234
123
12
3. Character pattern
for i in range(1,6):
A=65
for j in range(0,i):
print(chr(A),end="")
A=A+1
print()
Output :
AB
ABC
ABCD
ABCDE
Q5. Determine whether a number is a perfect number, an Armstrong number
or a palindrome.
sum = 0
for i in range(1,n):
if n%i==0:
sum = sum + i
if sum == n :
else :
temp = n
total = 0
temp = temp//10
if n == total:
temp = n
rev = 0
while n > 0:
d = n % 10
n = n//10
if temp == rev :
else :
Output :
28 is perfect number
elif n>1 :
for i in range(2,n):
if(n%i == 0):
break
else:
else :
Output :
def fib(n):
a=0
b=1
if n == 1:
print(a)
else:
print(a)
print(b)
for i in range(2,n):
c=a+b
a=b
b=c
print(c)
fib(10)
Output :
0 1 1 2 3 5 8 13 21 34
Q8. (a) Write a program to input the value of x and n and print the sum of
the following series: ⮚
1+𝑥+𝑥2+𝑥3+𝑥4+⋯𝑥𝑛
print("write a program to input the value of xand n and print the sum of the \n")
print("following series:1+x+x^2+x^3+x^4+.....x^n")
s=0
for i in range(n+1):
k=x**i
s=s+k
Output :
𝑥 +𝑥2!+𝑥3!+𝑥4!+ ⋯𝑥n
sum = x
for i in range(2, n + 1) :
fact=1
for j in range(i,1,-1):
fact=fact*j
nextterm= (x**i)/fact
if i%2==0:
sum=sum+nextterm
else:
sum=sum-nextterm
Output :
x = n1
y = n2
while(n2!=0):
t = n2
n2 = n1 % n2
n1 = t
gcd = n1
lcm = (x*y)/gcd
Output :
GCD of 22 and 55 = 11
Str="GeeksForGeeks"
lower=0
upper=0
for i in Str:
if(i.islower()):
lower+=1
else:
upper+=1
Output :
def isPalindrome(s):
return s == s[::-1]
# Driver code
s = "malayalam"
ans = isPalindrome(s)
if ans:
print("Yes")
else:
print("No")
Output : Yes
Q 12. Python program to find the largest/ smallest number in a list/tuple
listn = []
listn.append(element)
Output
Enter elements: 56
Enter elements: 44
Enter elements: 33
Enter elements: 77
Q13. Input a list of numbers and swap elements at the even location with the
elements at the odd location.
# Driver function
List = [23, 65, 19, 90]
pos1, pos2 = 1, 3
Output:
Output :
Enter number of students: 5
Enter Details of student No. 1
Roll No: 1
Student Name: riya
Marks: 55
Enter Details of student No. 2
Roll No: 2
Student Name: rahul
Marks: 88
Enter Details of student No. 3
Roll No: 3
Student Name: mohit
Marks: 76
Enter Details of student No. 4
Roll No: 4
Student Name: sneha
Marks: 65
Enter Details of student No. 5
Roll No: 5
Student Name: neha
Marks: 90
{1: ['riya', 55], 2: ['rahul', 88], 3: ['mohit', 76], 4: ['sneha', 65], 5: ['neha', 90]}
Student's name who get more than 75 marks is/are rahul
Student's name who get more than 75 marks is/are mohit
Student's name who get more than 75 marks is/are neha