CLASS 11-COMPUTER SCIENCE PRACTICAL -FT
CLASS 11-COMPUTER SCIENCE PRACTICAL -FT
Ans:
if i.islower():
lowercase +=1
s=s.lower()
for i in range(0,len(s)):
ch=s[i]
if(ch>='a' and ch<='z'):
if(ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u'):
vowels+=1
else:
consonants+=1
Output:
Enter Your String : Python
Number of Vowels in this String = 1
Number of Consonants in this String = 5
Number of Uppercase characters in this String = 1
Number of Lowercase characters in this String = 5
13. Write a program to input the value of x and n and print the sum of the following
series:
1 + 𝑥 + 𝑥 2 + 𝑥 3 + 𝑥 4 + ⋯ 𝑥n
Ans:
x=int(input("Input X "))
n=int(input("Input N "))
sum=0
for i in range(n):
sum+=x**i
print("The total is", sum)
Output
Input X 2
Input N 4
The total is 15
14. Write a program to input the value of x and n and print the sum of the following
series:
1 − 𝑥 + 𝑥 2 − 𝑥 3 + 𝑥 4 − ⋯ 𝑥n
Ans:
x=int(input("Input X"))
n=int(input("Input N"))
sum=0
for i in range(n):
if i%2==0:
sum+=x**i
else:
sum-=x**i
print("The total is",sum)
Output:
Input X2
Input N4
The total is -5
15. Write a program to input the value of x and n and print the sum of the following
series:
𝑥 + 𝑥 2 /2 + 𝑥 3 /3 + 𝑥 4 /4 + ⋯ 𝑥 𝑛 /n
Ans:
x=int(input("Input X"))
n=int(input("Input N"))
sum=0
for i in range(1,n):
if i%2!=0:
sum+=(x**i)/i
else:
sum-=(x**i)/i
print("The total is",sum)
Output:
Input X2
Input N4
The total is 2.6666666666666665
16. Write a program to input the value of x and n and print the sum of the
following series:
𝑥 + 𝑥 2/ 2! + 𝑥 3/ 3! + 𝑥 4/ 4! + ⋯ 𝑥 𝑛/ 𝑛!
Ans:
n=int(input("Input N"))
x=int(input("Input X"))
s=x
f=1
for i in range(1,n):
z=i+1
f=f*z
if i%2==0:
s-=((x**z)/f)
else:
s+=((x**z)/f)
print("The total is",s)
Output:
Input N 4
Input X 2
The total is 3.3333333333333335
17. Compute the greatest common divisor and least common multiple of two
integers.
Ans:
a=int(input("Enter a"))
b=int(input("Enter b"))
lcm=a*b
while(b!=0):
z=a%b
a=b
b=z
print("HCF or GCD",a)
lcmres=lcm/a
print("LCM:",lcmres)
Output:
Enter a190
Enter b24
HCF or GCD 2
LCM: 2280.0
Ans:
st=input("Enter a String:").lower()
s=""
for i in range(len(st)-1,-1,-1):
s+=st[i]
print("Check",s)
if st==s:
print("Palindrome")
else:
print("Not Palindrome")
Output:
Enter a String:mom
Check mom
Palindrome
Enter a String:Mother
Check rehtom
Not Palindrome
19. Input a list of numbers and swap elements at the even location with the
elements at the odd location.
Ans:
l=eval(input("Enter a list"))
for i in range(0,len(l)-1,2):
l[i],l[i+1]=l[i+1],l[i]
print("After changes List is:",l)
Output:
Enter a list[10,11,12,13,14,16,19,89,87]
After changes List is: [11, 10, 13, 12, 16, 14, 89, 19, 87]
20. Write a program to enter names of employees and their salaries as input and
store them in a dictionary.
Ans:
num = int(input("Enter the number of employees whose data to be stored: "))
count = 1
employee = dict()
while count <= num:
name = input("Enter the name of the Employee: ")
salary = int(input("Enter the salary: "))
employee[name] = salary
count += 1
print("\n\nEMPLOYEE_NAME\tSALARY")
for k in employee:
print(k,'\t\t',employee[k])
Output:
Enter the number of employees whose data to be stored: 4
Enter the name of the Employee: Ram
Enter the salary: 10000
Enter the name of the Employee: Rahul
Enter the salary: 20000
Enter the name of the Employee: Raj
Enter the salary: 30000
Enter the name of the Employee: Rajan
Enter the salary: 40000
EMPLOYEE_NAME SALARY
Ram 10000
Rahul 20000
Raj 30000
Rajan 40000
21. Write a program to count the number of times a character appears in a given
string.
Ans:
Output:
Enter a string: Asansol
A:1
s:2
a:1
n:1
o:1
l:1
22. Create a dictionary with the roll number, name and marks of n students in a
class and display the names of students who have marks above 75.
Ans:
n=int(input("Total number of students "))
d={}
for i in range(n):
rollno=int(input("Enter Roll Number "))
name=input("Enter Name ")
marks=float(input("Enter marks "))
d[rollno]=[name,marks]
print(d)
for i in d:
if d[i][1]>75:
print("Name= ",d[i][0], "\nmarks=",d[i][1])
Output:
Total number of students 3
Enter Roll Number 1
Enter Name ashok
Enter marks 75
Enter Roll Number 2
Enter Name faruk
Enter marks 75.1
Enter Roll Number 3
Enter Name dona
Enter marks 90
{1: ['ashok', 75.0], 2: ['faruk', 75.1], 3: ['dona', 90.0]}
Name= faruk
marks= 75.1
Name= dona
marks= 90.0