CS - 11 - CS - Practical List With Program & Output
CS - 11 - CS - Practical List With Program & Output
CLASS-XIth (ABCD)
1. WAP to Input two numbers and display the larger / smaller number.
Ans #WAP to Input two numbers and display the larger / smaller number
if num1>num2:
elif num2>num1:
Output
2. WAP to Input three numbers and display the largest / smallest number.
Ans # WAP to Input three numbers and display the largest / smallest number
else:
output
average_number=((num1+num2)/2)
output
num1,num2=num2,num1
print('num1=',num1)
print('num2=',num2)
output
num1= 12
num2= 6
if num>0:
print("Number is positive")
elif num<0:
print("Number is Negative")
else:
print("Number is zero")
output
Number is positive
if Colour=='Green':
print("Go")
elif Colour=='Red':
print("Stop")
elif Colour=='Yellow':
else:
output
Stop
a = int(input("Enter a number to get the Square root")) # take an input function and pass the
variable a.
print("Square root of the number is", res) # print the Square Root
output
8. WAP to print numbers in the range from 1 to 20 (Use for loop sts).
Ans # WAP to print numbers in the range from 1 to 20 (Use for loop sts)
for i in range(1,21):
print(i,end=” ”)
output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
9. WAP to accept a number n from the user & print its table.
Ans
number = int(input ("Enter the number of which the user wants to print the multiplication
table: "))
count = 1
output
Enter the number of which the user wants to print the multiplication table: 3
3x1=3
3x2=6
3x3=9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30
10. Write the while loop to print the series:- 5, 10, 15, 20, ………………………………….100.
Ans
i=5
while i<=100:
print(i)
i=i+5
output
10
15
20
25
30
35
40
45
50
55
60
65
70
75
80
85
90
95
100
a) *
**
***
****
*****
Ans
for i in range(1,Rows+1):
for j in range(i):
print('*',end=" ")
print()
output
**
***
****
*****
b) A
AB
ABC
ABCD
ABCDE
Ans
# inner loop
for j in range(65,i+1):
print(chr(j),end="")
print()
output
AB
ABC
ABCD
ABCDE
12. Write a program to input a string from the user and print it in the reverse order without
creating a new string.
Ans
print(st[i],end=" ")
output
Enter the string:-3456755644
4465576543
13. Write a program using a user defined function to check if a string is a palindrome or not. (A
string is called palindrome if it reads same backwards as forward. For example, Kanak is a
palindrome.).
Ans
def checkpalin(st):
i=0
j=len(st) -1
while(i<=j):
if (st[i] !=st[j]):
return False
i+=1
j-=1
return True
st=input("Enter a string:-")
results = checkpalin(st)
if results==True:
else:
output
Enter a string:-kanak
n1,n2=0,1
count=0
if nterm<=0:
elif nterm==1:
print(n1)
else:
print("fibonacci sequence:")
while count<nterm:
print(n1)
nth=n1+n2
#update values
n1=n2
n2=nth
count+=1
output
fibonacci sequence:
2
3
13
21
34
15. Program to count the total number of vowels and consonants in a string.
vowels=['a','e','i','o','u']
str=input("Enter a string").lower()
v_ctr=0
c_ctr=0
for x in str:
if x in vowels:
v_ctr+=1
else:
c_ctr+=1
print("vowels:",v_ctr)
print("consonants",c_ctr)
output
consonants 6