0% found this document useful (0 votes)
6 views

17385

The document contains a list of 22 computer science programs for grade 11, each demonstrating different programming concepts such as number manipulation, string processing, and data structures. Examples include calculating sums of digits, converting numbers to binary, checking for prime and perfect numbers, and manipulating lists and dictionaries. Each program includes user input, processing logic, and output examples.

Uploaded by

buvambhaam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

17385

The document contains a list of 22 computer science programs for grade 11, each demonstrating different programming concepts such as number manipulation, string processing, and data structures. Examples include calculating sums of digits, converting numbers to binary, checking for prime and perfect numbers, and manipulating lists and dictionaries. Each program includes user input, processing logic, and output examples.

Uploaded by

buvambhaam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

​ ​ ​ ​ ​ COMPUTER SCIENCE

​ ​ ​ ​ ​ PROGRAMS LIST - GRADE 11

#Program 8:
# Read a four-digit number and find the sum of first two and last two digits.

num = int(input('Enter first number: '))


if num < 1000 and num > 9999:
print(num, 'is not a four-digit number.')
exit(0)

l = []
n = num

while n != 0:
l.insert(0, n % 10)
n = n // 10

print('Sum of first two digits:', l[0] + l[1])


print('Sum of last two digits:', l[2] + l[3])

Output:
Enter first number: 1234
Sum of first two digits: 3
Sum of last two digits: 7

#Program 9:
# Read a number from the user and convert to its equivalent binary number.

num = int(input('Enter a number: '))


n = num
s = ''
while n != 0:
s = str(n % 2) + s
n = n // 2
print('Binary equivalent of', num, 'is', s)

Output:
Enter a number: 121
Binary equivalent of 121 is 1111001
#Program 10:
# Read a number from the user and check if it is a prime number or not.

num = int(input('Enter number: '))

for i in range(2, num//2+1):


if num % i == 0:
print(num, 'is not prime.')
break
else:
print(num, 'is prime.')

Output1:
Enter number: 21
21 is not prime.
Output2:
Enter number: 5
5 is prime.

#Program 11:
# Read a number from the user and check if it is a perfect number or not.

num = int(input('Enter number: '))


sum = 0
for i in range(1, num//2+1):
if num % i == 0:
sum += i

if sum == num:
print(num, 'is a perfect number.')
else:
print(num, 'is not a perfect number.')

Output 1:
Enter number: 6
6 is a perfect number.

Output 2:
Enter number: 36
36 is not a perfect number.
#Program 12:
# Read two numbers from the user and compute their GCD and LCM.

def gcd(a, b):


i = common_div = 1
while i <= a and i <= b:
if a % i == 0 and b % i == 0:
common_div = i
i += 1
return common_div

def lcm(a, b):


return (a * b) // gcd(a, b)
n1 = int(input('Enter first number: '))
n2 = int(input('Enter second number: '))
print('GCD of', n1, 'and', n2, 'is', gcd(n1, n2))
print('LCM of', n1, 'and', n2, 'is', lcm(n1, n2))

Output:
Enter first number: 45
Enter second number: 5

GCD of 45 and 5 is 5
LCM of 45 and 5 is 45

#Program 13:
#Program to find the sum of the series:
# x + x2/ 2! - x3/3! + x4/ 4! - x5/ 5! +............+ xn/ n!

x=int(input("enter the value of x :"))


n=int(input("enter the nth value :"))
sum=x
prod=1
i=2
while i<=n:
prod=prod*i
if i%2==0:
sum=sum+(x**i)/prod
else:
sum=sum-(x**i)/prod
i=i+1
print("The sum of the series=",sum)
Output:

enter the value of x: 2


enter the nth value: 5
The sum of the series= 3.066666666666667

#Program 14:
'''Program to display the pattern
12345
1234
123
12
1
'''
n=int(input("enter the number of lines:"))

for i in range(n):
for j in range(1,n-i+1):
print(j,end=" ")
print()

Output:

1 2345
1 234
1 23
1 2
1
#Program 15:
#Program to read a string and display count of:
#1. Number of vowels
#2. Number of consonants
#3. Number of uppercase letters
#4. Number of lowercase letters

mystring = input('Enter a string: ')

vowel = consonant = upper = lower = 0


for char in mystring:
asciival = ord(char)
if asciival in range(65, 91):
upper += 1
if char in ['A', 'E', 'I', 'O', 'U']:
vowel += 1
else:
consonant += 1
elif asciival in range(97, 123):
lower += 1
if char in ['a', 'e', 'i', 'o', 'u']:
vowel += 1
else:
consonant += 1

print('No. of vowels:', vowel)


print('No. of consonants:', consonant)
print('No. of uppercase letters:', upper)
print('No. of lowercase letters:', lower)

Output:

Enter a string: Vyasa International School


No. of vowels: 10
No. of consonants: 14
No. of uppercase letters: 3
No. of lowercase letters: 21
#Program 16:
#Program to read a string and find the shortest word.

mystring = input('Enter a string: ')


lst = mystring.split(' ')
shortestWord = ' '

for word in lst:


if len(word) < len(shortestWord):
shortestWord = word

print('Shortest word is', shortestWord)

Output:

Enter a string: Vyasa International School


Shortest word is Vyasa

#Program 17:
#Program to input a list of numbers and swap elements at the even location with the
#elements at the odd location.

l = eval(input('Enter a list of numbers: '))

print('List before swapping:', l)

i=0
while i < len(l) - 1:
l[i], l[i+1] = l[i+1], l[i]
i += 2

print('List after swapping:', l)

Output:

Enter a list of numbers: [1,2,3,4,5]


List before swapping: [1, 2, 3, 4, 5]
List after swapping: [2, 1, 4, 3, 5]

Enter a list of numbers: [1,2,3,4,5,6]


List before swapping: [1, 2, 3, 4, 5, 6]
List after swapping: [2, 1, 4, 3, 6, 5]
#Program 18:
#Program to input a list/tuple of elements, search for a given element in the list/tuple.
#If the element exists, print the position of the element, else print not found.

l = eval(input('Enter the list of numbers: '))


n = int(input('Enter the number to search for: '))

if n in l:
print(n,'is at position', l.index(n) + 1)
else:
print(n, 'does not exist in the collection.')

Output:

Enter the list of numbers: [1,2,3,4,5]


Enter the number to search for: 3
3 is at position 3

Enter the list of numbers: [1,2,3,4,5]


Enter the number to search for: 9
9 does not exist in the collection.

#Program 19:
#Program that inputs two tuples and prints True if element in first tuple is also
#an element of the second tuple, else prints False.

t1 = eval(input('Enter first sequence: '))


t2 = eval(input('Enter second sequence: '))

isSubset = False

for item in t1:


if item not in t2:
break
else:
isSubset = True

if isSubset:
print('First sequence is a subset of second sequence')
else:
print('First sequence is not a subset of second sequence')
Output:

Enter first sequence: (2,3)


Enter second sequence: (1,2,3,4,5)
First sequence is a subset of second sequence

Enter first sequence: (5,6)


Enter second sequence: (1,2,3,4,5)
First sequence is not a subset of second sequence

#Program 20:
#Program that creates the following tuple using a for loop ('a', 'b', 'c', 'd' . . .), and then
#modify it as ('a', 'bb', 'ccc', 'dddd', . . . .) that ends with 26 copies of the letter z.

t = ()
for i in range(97, 123):
t = t + tuple(chr(i))

print('Tuple before:', t)

l = list(t)

i=1
while i < len(l):
l[i] = l[i] * i
i += 1

t = tuple(l)
print('Tuple after:', t)

Output:

Tuple before: ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z')

Tuple after: ('a', 'b', 'cc', 'ddd', 'eeee', 'fffff', 'gggggg', 'hhhhhhh', 'iiiiiiii', 'jjjjjjjjj', 'kkkkkkkkkk',
'lllllllllll', 'mmmmmmmmmmmm', 'nnnnnnnnnnnnn', 'oooooooooooooo',
'ppppppppppppppp', 'qqqqqqqqqqqqqqqq', 'rrrrrrrrrrrrrrrrr', 'ssssssssssssssssss',
'ttttttttttttttttttt', 'uuuuuuuuuuuuuuuuuuuu', 'vvvvvvvvvvvvvvvvvvvvv',
'wwwwwwwwwwwwwwwwwwwwww', 'xxxxxxxxxxxxxxxxxxxxxxx',
'yyyyyyyyyyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzzzzzzzzzzz')
#Program 21:
#Program that creates 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.

n = int(input('Enter no of students: '))


l = []
for i in range(n):
print('Enter the details for student', i + 1, ': ')
d = {}
d['rollno'] = input('Enter the roll no: ')
d['name'] = input('Enter the name: ')
d['marks'] = int(input('Enter the marks: '))
l.append(d)

print('Students whose marks are above 75 are:')


for student in l:
if student['marks'] > 75:
print(student)

Output:

Enter no of students: 3
Enter the details for student 1 :
Enter the roll no: 100
Enter the name: Aryan
Enter the marks: 91
Enter the details for student 2 :
Enter the roll no: 101
Enter the name: Varun
Enter the marks: 67
Enter the details for student 3 :
Enter the roll no: 102
Enter the name: Dhruv
Enter the marks: 75
Students whose marks are above 75 are:
{'rollno': '100', 'name': 'Aryan', 'marks': 91}
#Program 22:
#Program that has a dictionary D1 which has values in the form of a list of numbers.
#Write a program to create a new dictionary D2 having same keys as D1 but values as
#the sum of the list elements.

D1 = {'A': [1, 2, 3], 'B': [4, 5, 6]}


D2 = D1.copy()
for key in D2:
D2[key] = sum(D2[key])

print(D1)
print(D2)

Output:

{'A': [1, 2, 3], 'B': [4, 5, 6]}


{'A': 6, 'B': 15}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy