Class 11 CBSE Computer Science General Practical
Class 11 CBSE Computer Science General Practical
Aim:
To Write Python program to input a welcome message and print it
Program:
message=input( " Enter welcome message: " )
print("Hello, ",message)
hi Hello
Result:
(num1>num2):
Output :
number is 88
Q3. Python Program to input 2 numbers and display Smaller number
(num1<num2):
Output :
range(i):
print('*',end='') print('')
Output :
**
***
****
*****
******
*******
********
*********
1. #Number Pattern
Output :
12345
1234
123
12
1. 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 :
A
AB
ABC
ABCD
ABCDE
range(1,n):
if n%i==0:
sum = sum + i
if sum == n :
total = 0
%10
temp//10
if n == total:
else :
n > 0:
d = n % 10
if temp == rev :
Output :
Enter any number to check whether it is perfect ,armstrong or palindrome :
28 28 is perfect number
palindrome number
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: ⮚
print("write a program to input the value of xand n and print the sum of the \n")
s=s+k
Output :
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
characters is:",upper)
Output :
is: 3
Q11. Input a string and determine whether it is a palindrome or not; convert the
case of characters in a string
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
for i in range(5):
value = int(input())
mylist.append(value)
print("Enter an element to be search: ")
element = int(input())
for i in range(5):
if element == mylist[i]:
print("\nElement found at Index:", i)
print("Element found at Position:", i+1)
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