Professional Documents
Culture Documents
Practical Assignment Xi SC (CS) - 2022-23
Practical Assignment Xi SC (CS) - 2022-23
XI SCIENCE (JEE-NEET-BOARD)
COMPUTER SCIENCE-(083)
FOR THE SESSION-2022-23
output
Enter welcome message : India
Hello, India
output
Enter the first number: 10
Enter the second number: 20
20 s greater
output
Enter First Number 10
Enter Second Number 20
Enter Third Number 15
The Largest number is 20
1
Pattern-1
output
*
* *
* * *
* * * *
* * * * *
Pattern-2
# This is the example of print simple pyramid pattern
rows = 5
# outer loop to handle number of rows
for i in range(0,rows,1):
# inner loop to handle number of columns
# values is changing according to outer loop
for j in range(1,6-i,1):
# printing numbers
print(j, end=' ')
# ending line after each row
print()
output
Pattern-3
# This is the example of print simple pyramid pattern
rows = 5
# outer loop to handle number of rows
2
for i in range(1,rows+1,1):
# inner loop to handle number of columns
# values is changing according to outer loop
a=65
for j in range(1,i+1,1):
# printing numbers
print(str(a), end=' ')
a+=1
# ending line after each row
print()
output
def palindrome(n):
temp = n #temp is taken as input
rev = 0 #reverse is 0
while n > 0: #if n is greater than 0 this loop runs
dig = n % 10
rev = rev * 10 + dig
n = n // 10
if temp == rev:
print(temp, "The number is a palindrome!")
else:
print(temp, "The number isn't a palindrome!")
def armstrong(n):
count = 0
temp = n
while temp > 0:
digit = temp % 10
count += digit ** 3
temp //= 10
if n == count:
print(n, "is an Armstrong number")
else:
print(n, "is not an Armstrong number")
def perfect(n):
count = 0
for i in range(1, n):
if n % i == 0:
count = count + i
if count == n:
print(n, "The number is a Perfect number!")
else:
print(n, "The number is not a Perfect number!")
n = int(input("Enter number:"))
3
palindrome(n)
armstrong(n)
perfect(n)
8. Compute the greatest common divisor and least common multiple of two
integers.
4
a = temp
hcf = a
lcm = int((no*nt)/hcf)
print("\nLCM (" + str(no) + ", " + str(nt) + ") = ", lcm)
print("HCF (" + str(no) + ", " + str(nt) + ") = ", hcf)
9. Count and display the number of vowels, consonants, digit, special characters in
string.
# Python3 Program to count vowels,
# consonant, digits and special
def countCharacterType(str):
vowels = 0
consonant = 0
specialChar = 0
digit = 0
ch = str[i]
print("Vowels:", vowels)
print("Consonant:", consonant)
print("Digit:", digit)
print("Special Character:", specialChar)
# Driver function.
str = "Vikasites121"
countCharacterType(str)
string=raw_input("Enter string:")
5
if(string==string[::-1]):
print("The string is a palindrome")
else:
print("The string isn't a palindrome")
st = []
num = int(input('How many numbers: '))
for n in range (num):
numbers = int(input('Enter number '))
lst.append(numbers)
print("Maximum element in the list is :", max(lst))
print(“Minimum element in the list is :", min(lst))
12. Input a list of numbers and swap elements at the even location with the elements
at the odd location.
13. Input a list/tuple of elements, search for a given element in the list/tuple.
mylist = []
print("Enter 5 elements for the list: ")
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)
14. Create a dictionary with the roll number, name and marks of n students in a class
and display the names of students who have scored marks above 75.
n=int(input("Enter n: "))
d={}
for i in range(n):
roll_no=int(input("Enter roll no: "))
name=input("Enter name: ")
6
marks=int(input("Enter marks: "))
d[roll_no]=[name,marks]
for k in d:
if(d[k][1]>75):
print(d[k][0])
16. Write a Python program to iterate over dictionaries using for loops
18. Write a Program to remove the empty list from a list of lists.
7
# Getting list from user
myList = []
length = int(input("Enter number of elements : "))
for i in range(0, length):
value = int(input())
myList.append(value)
# Printing lists
print("Entered List ", myList)
print("Cumulative sum List ", cumList)
# initializing list
test_list = [[(4, 5), (7, 8)], [(10, 13), (18, 17)], [(0, 4), (10, 1)]]
x=[]
for i in test_list:
for j in i:
j=list(j)
x.extend(j)
re1=[]
re2=[]
for i in range(0,len(x)):
if(i%2==0):
re1.append(x[i])
else:
re2.append(x[i])
res=[]
res.append(tuple(re1))
res.append(tuple(re2))
# printing result
print("The converted tuple list : " + str(res))