CBSE COMPUTER SCIENCE
Відкрити в Telegram
QUESTION BANK, REFERENCE BOOK, LAB MANUAL , WORKSHEET ETC., PYTHON TEXT BOOK AND REFERENCE BOOKS, 01. ASK QUESTIONS AT https://t.me/joinchat/FJ1noGs-64I0OWI1
Показати більше549
Підписники
Немає даних24 години
Немає даних7 днів
Немає даних30 день
Архів дописів
a=10
def call():
global a
a=15
b=20
print(a)
def Check(n1=1,n2=2):
n1=n1+n2
n2+=1
print(n1,n2)
Check()
Check(2,1)
Check(3)
call()
15
3 3
3 2
5 3
Text1="CBSE BOARD 2023"
Text2=""
I=0
while I<len(Text1):
if Text1[I]>="0" and Text1[I]<="9":
Val = int(Text1[I])
Val = Val + 1
Text2=Text2 + str(Val)
elif Text1[I]>="A" and Text1[I] <="Z":
Text2=Text2 + (Text1[I+1])
else:
Text2=Text2 + "*"
I=I+1
print(Text2)
BSE *OARD *3134
Msg1="WeLcOME"
Msg2="GUeSTs"
Msg3=""
for I in range(0,len(Msg2)+1):
if Msg1[I]>="A" and Msg1[I]<="M":
Msg3=Msg3+Msg1[I]
elif Msg1[I]>="N" and Msg1[I]<="Z":
Msg3=Msg3+Msg2[I]
else:
Msg3=Msg3+"*"
print(Msg3)
G*L*TME
def gfg(x,l=[]):
for i in range(x):
l.append(i*i)
print(l)
gfg(2)
gfg(3,[3,2,1])
gfg(3)
[0, 1]
[3, 2, 1, 0, 1, 4]
[0, 1, 0, 1, 4]
def power (b , p):
r = b ** p
return r
def calcSquare(a):
a = power (a, 2)
return a
n = 5
result = calcSquare(n)
print (result )
25
list1 =[1998, 2002, 1997, 2000]
list2 =[2014, 2016, 1996, 2009]
print("list1 + list 2 = : ", list1 +list2) #statement 1
print("list1 * 2 = : ", list1 *2) #statement 2
list1 + list 2 = : [1998, 2002, 1997, 2000, 2014, 2016, 1996, 2009]
list1 * 2 = : [1998, 2002, 1997, 2000, 1998, 2002, 1997, 2000]
my_dict = {}
my_dict[1] = 1
my_dict['1'] = 2
my_dict[1.0] = 4
sum = 0
for k in my_dict:
sum += my_dict[k]
print (sum)
6
my_dict = {}
my_dict[(1,2,4)] = 8
my_dict[(4,2,1)] = 10
my_dict[(1,2)] = 12
sum = 0
for k in my_dict:
sum += my_dict[k]
print (sum)
print(my_dict)
30
{(1, 2, 4): 8, (4, 2, 1): 10, (1, 2): 12}
Pandas Series 1 : https://forms.gle/a8EdFHuH9FCRKSxw9
Pandas Series 2 : https://forms.gle/8Ndj9Y1VYY4bPyaf8
Pandas Series 3 : https://forms.gle/affXAyoXxjkCqFAY9
Pandas Series 4 : https://forms.gle/YbPqQ8fPERxNRmWa7
https://docs.google.com/forms/d/e/1FAIpQLSfjzip1pbIuard6v4ypwWEHCva1c2XYs5XbhPjl7O8mZ5dUcg/viewform?usp=sf_link
Online Class : https://docs.google.com/forms/d/e/1FAIpQLSeRkJ9rhxQxJNEumkDTDhHd-pkeMIWZdNa5yxFQmEgv9YxSnQ/viewform?usp=sf_link
https://forms.gle/TUSoNMLqeejBJxQf8
SSJ/2- SET-$ Tentative t.me/QuizBot?start=mr6DO8hs
SSJ/2- SET-$ Tentative A t.me/QuizBot?start=mr6DO8hs
PYTHON : FILE HANDLING - 5 t.me/QuizBot?start=ohtwqD6S
PYTHON : FILE HANDLING - 4 t.me/QuizBot?start=MnPrt2v4
PYTHON : FILE HANDLING - 3 t.me/QuizBot?start=7VvdcQtz
PYTHON : FILE HANDLING - 2 t.me/QuizBot?start=vx12PVG3
PYTHON : FILE HANDLING -1 t.me/QuizBot?start=nQD1Q3kG
PYTHON : LIST-3 t.me/QuizBot?start=Smn9ThxH
PYTHON : LIST-2 t.me/QuizBot?start=k8DYZ3Oa
PYTHON : LIST-1 t.me/QuizBot?start=eowBkzeL
PYTHON BASICS - 1 t.me/QuizBot?start=ayrNqFKS
import random
# random number from 0 to 1
print(random.random())
# Output 0.16123124494385477
# random number from 10 to 20
print(random.randint(10, 20))
# Output 18
# random number from 10 to 20 with step 2
print(random.randrange(10, 20, 2))
# Output 14
# random float number within a range
print(random.uniform(5.5, 25.5))
# Output 5.86390810771935
# random choice from sequence
print(random.choice([10, 20, 30, 40, 50]))
# Output 30
# random sample from sequence
print(random.sample([10, 20, 30, 40, 50], k=3))
# Output [50, 10, 20]
# random sample without replacement
print(random.choices([10, 20, 30, 40, 50], k=3))
# Output [30, 10, 40]
# random shuffle
x = [10, 20, 30, 40, 50, 60]
random.shuffle(x)
print(x)
# [60, 10, 30, 20, 50, 40]
# random seed
random.seed(2)
print(random.randint(10, 20))
# 10
random.seed(2)
print(random.randint(10, 20))
# 10
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:39]
7 Python Program to Calculate Profit or Loss
actual_cost = float(input(" Enter the Actual Product Price: "))
sale_amount = float(input(" Enter the Sales Amount: "))
if(actual_cost > sale_amount):
amount = actual_cost - sale_amount
print("Total Loss Amount = {0}".format(amount))
elif(sale_amount > actual_cost):
amount = sale_amount - actual_cost
print("Total Profit= {0}".format(amount))
else:
print("No Profit No Loss!!!")
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:39]
8 Python program To find third largest/ smallest
number in a list
nlist = []
n = int(input("Enter the Total Number of List Elements: "))
for i in range(1, n + 1):
value = int(input("Enter the Value of %d Element : " %i))
nlist.append(value)
sorted_list = sorted(nlist)
print("Sorted elements in list : ",sorted_list)
print("The Third Smallest Element in this List is : ", sorted_list[2])
print("The Third Largest Element in this List is : ", sorted_list[-3])
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:40]
9 PythonProgramtoCalculateMonthlyEMI
p = float(input("Enter principal amount: "))
R = float(input("Enter annual interest rate: "))
n = int(input("Enter number of months: " ))
r = R/(12*100)
emi = p * r * ((1+r)**n)/((1+r)**n - 1)
print("Monthly EMI = ", emi)
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:38]
2Tocalculateperimeter/circumferenceandareaofshapessuchastriangle,
rectangle,squareandcircle
import math
# creating options
while True:
print("\nMAIN MENU")
print("1. Calculate Area and Parameter of square")
print("2. Calculate Area and Perimeter of circle")
print("3. Calculate Area and Perimeter of rectangle")
print("4. Calculate Area and Perimeter of triangle")
print("5. Exit")
choice = int(input("Enter the Choice:"))
if choice == 1:s=float(input("Enter the side of square:"))
# Calculating area of square (aos)
print("\nCALCULATE AREA OF SQUARE")
aos=float(s*s);
print("Area of square is:",aos)
print("\nCALCULATE PERIMETER OF SQUARE")
# Calculating perimeter of square (pos)
pos=float(4*s);
print("Perimeter of square is:",pos)
break
if choice ==2:
r=float(input("Enter the radius of circle:"))
# Calculating area of circle (aoc)
aoc=float(3.14*r*r);
print("Area of circle is:",aoc)
# Calculating perimeter of square (pos)
poc=float(2*3.14*r);
print("Perimter of circle is:",poc)
break
if choice ==3:
l=float(input("Enter the length of rectangle:"))
b=float(input("Enter the breadth of rectangle:"))
# Calculating area of rectangle (aor)
aor=float(l*b);
print("Area of rectangle is:",aor)
# Calculating perimeter of rectangle (por)
por=float(2*(l+b))
print("Perimter of rectangle is:",por)
break
if choice ==4:
bs=float(input("Enter the base of right angled triangle:"))
h=float(input("Enter the height of right angled triangle:"))
# Calculating area of triangle (aot)
aot=float((bs*h)/2);
print("Area of triangle is:",aot)
hypotenuse=float(math.sqrt(bs*bs+h*h))
# Calculating perimeter of right angle triangle (pot)
pot=float(bs+h+hypotenuse)print("Perimter of right angled triangle is:",pot)
break
else:
print("Oops! Please enter correct Choice.")
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:38]
3pythonprogramtocomputesimpleinterestandcompoundinterest.
p=float(input("Enter the principle amount:"))
n=int(input("Enter the time(years):"))
r=float(input("Enter the rate:"))
si=(p*n*r)/100
print("The simple interest is:",si)
ci = p * ((1 + (r / 100 ))** t) - p
print("Compound interest is %.2f" % ci)
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:38]
4Pythonprogramtofindsalepriceofanitemwithgivencostanddiscount
cp=float(input("Enter Cost Price : "))
ds=float(input("Enter discount % : "))discount=cp*ds/100
sp=cp-discount
print("Cost Price : ",cp)
print("Discount: ",discountamt)
print("Selling Price : ",sp)
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:38]
5 Python Program to Calculate Grade of a Student
sub1=int(input("Enter marks of the first subject: "))
sub2=int(input("Enter marks of the second subject: "))
sub3=int(input("Enter marks of the third subject: "))
sub4=int(input("Enter marks of the fourth subject: "))
sub5=int(input("Enter marks of the fifth subject: "))
avg=(sub1+sub2+sub3+sub4+sub4)/5
if(avg>=90):
print("Grade: A")
elif(avg>=80&avg<90):
print("Grade: B")
elif(avg>=70&avg<80):print("Grade: C")
elif(avg>=60&avg<70):
print("Grade: D")
else:
print("Grade: F")
Output
Enter marks of the first subject: 85
Enter marks of the second subject: 95
Enter marks of the third subject: 99
Enter marks of the fourth subject: 93
Enter marks of the fifth subject: 100
Grade: A
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:39]
6 Python program to find the largest and smallest number in a list
lst = []
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), "\nMinimum element in the
list is :", min(lst))
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:35]
1Pythonprogramtoprintmultipleofgivennumbersusingforloop
Source code
n = int(input("Enter number: "))
print("The multiples are: ")
for i in range(1,11):
print(n*i, end =" ")
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:35]
2 Python Program to Count the Number of Vowels
in a String
Source code
string=input("Enter string:")
vowels=0
for i in string:
if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or
i=='O' or i=='U'):
vowels=vowels+1
print("Number of vowels are:")
print(vowels)
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:36]
3 Python program to print the words starting
with particular alphabet in a user entered string
Source code
s = input("Enter any sentences : ")
a = input("Enter any alphabet to find :")
found = False
words = s.split()
for word in words:
if word.startswith(a):
print(word)
found = True
if (found == False):
print("No word starting with user entered alphabet")
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:36]
4 Python Program to Count Occurrence of a
Character in a String
Source code
string = input("Please enter your own String : ")
char = input("Please enter your own Character : ")
count = 0
for i in range(len(string)):if(string[i] == char):
count = count + 1
print("The total Number of Times ", char, " has Occurred = " , count)
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:36]
5Createadictionarytostorenamesofstateandtheircapitalsinpython
Source code
states = dict()
n = int(input("Enter the number of states :"))
for i in range(n):
state = input("Enter name of state :")
capital = input("Enter capital of state :")
states[state] = capital
print("Dictionary is created :",states)
t = input("Enter the name of state to display capital:")
print(states[t])
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:36]
6 Create a dictionary of students to store names
and marks obtained in five subjects in python
Source code
students = dict()
n = int(input("Enter number of students :"))
for i in range(n):
sname = input("Enter names of student :")
marks= []
for j in range(5):
mark = float(input("Enter marks :"))
marks.append(mark)
students[sname] = marks
print("Dictionary of student created :")
print(students)
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:37]
7 Python program to get the maximum and minimum value in a
dictionary.
Source code
my_dict = {'x':500, 'y':5874, 'z': 560}
key_max = max(my_dict.keys(), key=(lambda k: my_dict[k]))
key_min = min(my_dict.keys(), key=(lambda k: my_dict[k]))
print('Maximum Value: ',my_dict[key_max])
print('Minimum Value: ',my_dict[key_min])
S SHUNMUGA SUNDARAM, M.E, A.M.I.E, MISTE,. IAENGG, [29-11-2022 21:37]
1PythonprogramtocalculateGST/IncomeTax
p = float(input("Enter Original amount : "))
np = float(input("Enter net price : "))
# Calculating GST amount
GST_amount = np - p
# Calculating GST percentage
GST_percent = ((GST_amount * 100) / p)
print("GST = ",end='')
print(round(GST_percent),end='')
print("%")
3. import numpy as np
print(np.version)
print(np.show_config())
4. import numpy as np
x = np.array([1, 2, 3, 4])
print("Original array:")
print(x)
print("Test if none of the elements of the said array is zero:")
print(np.all(x))
x = np.array([0, 1, 2, 3])
print("Original array:")
print(x)
print("Test if none of the elements of the said array is zero:")
print(np.all(x))
5. import numpy as np
array=np.zeros(10)
print("An array of 10 zeros:")
print(array)
array=np.ones(10)
print("An array of 10 ones:")
print(array)
array=np.ones(10)*5
print("An array of 10 fives:")
print(array)
6. import numpy as np
m= np.arange(10,22).reshape((3, 4))
print("Original matrix:")
print(m)
print("Number of rows and columns of the said matrix:")
print(m.shape)
7. import numpy as np
x = np.array([[0,1],[2,3]])
print("Original array:")
print(x)
print("Sum of all elements:")
print(np.sum(x))
print("Sum of each column:")
print(np.sum(x, axis=0))
print("Sum of each row:")
print(np.sum(x, axis=1))
8. import numpy as np
a = [[1, 2], [3, 4]]
x = np.array(a)
a2 = x.tolist()
print(a == a2)
9. import numpy as np
x = np.arange(10)
print("Array from 0 to 9:")
print(x)
10. import numpy as np
import numpy as np
x = np.arange(12, 38)
print("Original array:")
print(x)
print("Reverse array:")
x = x[::-1]
print(x)
11. import numpy as np
x = np.ones((5,5))
print("Original array:")
print(x)
print("1 on the border and 0 inside in the array")
x[1:-1,1:-1] = 0
print(x)
12. import numpy as np
x = [10, 20, 30]
print("Original array:")
print(x)
x = np.append(x, [[40, 50, 60], [70, 80, 90]])
print("After append values to the end of the array:")
print(x)
13. import numpy as np
array1 = np.array([0, 10, 20, 40, 60])
print("Array1: ",array1)
array2 = [10, 30, 40]
print("Array2: ",array2)
print("Common values between two arrays:")
print(np.intersect1d(array1, array2))
14. import numpy as np
x = np.array([0, 1, 2])
y = np.array([2, 1, 0])
print("\nOriginal array1:")
print(x)
print("\nOriginal array1:")
print(y)
print("\nCovariance matrix of the said arrays:\n",np.cov(x, y))
15. import numpy as np
x = np.array([0, 1, 3])
y = np.array([2, 4, 5])
print("\nOriginal array1:")
print(x)
print("\nOriginal array1:")
print(y)
print("\nCross-correlation of the said arrays:\n",np.cov(x, y))
16. import numpy as np
x = np.arange(6)
print("\nOriginal array:")
print(x)
r1 = np.mean(x)
r2 = np.average(x)
assert np.allclose(r1, r2)
print("\nMean: ", r1)
r1 = np.std(x)
r2 = np.sqrt(np.mean((x - np.mean(x)) 2 ))
assert np.allclose(r1, r2)
print("\nstd: ", 1)
r1= np.var(x)
r2 = np.mean((x - np.mean(x)) 2 )
assert np.allclose(r1, r2)
print("\nvariance: ", r1)
17. import numpy as np
x = np.random.randint(low=10, high=30, size=6)
print(x)
