Write A Program That Multiplies Two Integer Numbers Without Using Operator, Using Repeated Addition
Write A Program That Multiplies Two Integer Numbers Without Using Operator, Using Repeated Addition
1
2. Write a program to create a dictionary
containing names of competitions winner students
as keys and number of their wins as values.
n=int(input("How many students:"))
CompWinners={}
for a in range(n):
key=input("Name of the student:")
value=int(input("Number of
competitions won:"))
CompWinners[key]=value
print("The dictionary now is:")
print(CompWinners)
2
3.Write a program that finds an element’s
index/position in tuple WITHOUT using
index().
tuple1=('A', ‘N’, ‘S’, ‘H’, ’G’, ‘A’, ‘U’,
‘R’)
char=input("Enter a single letter without
quotes:")
if char in tuple1:
count=0
for a in tuple1:
if a !=char:
count+=1
else:
break
print(char, "is at index", count, "in",
tuple1)
else:
print(char, "is NOT in", tuple1)
3
4. Write a program that checks for presense of
a value inside a dictionary and prints its key.
info={'Ansh':'CSc.', 'Mark':'Eco',
'Kamesh':'Eng', 'Gaur':'Env.Sc'}
inp=input("Enter value to be searched
for:")
if inp in info.values():
for a in info:
if info[a]==inp:
print("The key of given value
is", a)
break
else:
print("Given value does not exist
in dictionary")
4
5. Write a program to sort a sequence using
insertion sort.
def insertion_sort(alist):
temp = alist[i]
j=i-1
alist[j + 1] = alist[j]
j=j-1
alist[j + 1] = temp
insertion_sort(alist)
print(alist)
5
6. Write a program that takes string with
multiple words and then capitalize first letter of
each word and forms a new strings out of it.
string = input("Enter a string:")
length = len(string)
a = 0
end = length
string2='' #empty string
while a < length :
if a == 0:
string2 += string[0].upper()
a += 1
elif (string[a] =='' and string[a+1] !=''):
string2 += sting[a]
string1 += string[a+1].upper()
a += 2
else :
string2 += string[a]
a += 1
print("Original String:", string)
print("Capitalized words String", string2)
6
7. Write a program that reads a string and
checks whether it is a palindrome string or not.
a=input("Enter String:")
b=a[-1::-1]
if(a==b):
print("Palindrome String")
else:
print("Not Palindrome String")
7
8. What is the output produced by the following
code snippet.
aLst=[1,2,3,4,5,6,7,8,9]
print(aLst[::3])
8
9.Write a program to calculate simple
interest using a function interest().
def interest(principal, time, rate):
return principal*rate/100*time
#_main_
roi=float(input("Enter rate of
interest(ROI):"))
si=interest(prin,roi,time)
9
10.Write a function that receive an octal number
and prints the quivalent number in the other
number bases i.e., in decimal, binary, and
hexadecimal equivalents.
def oct2others(n):
numString=str(n)
decNum=int(numString, 8)
print("Number in Hexadecimal:",
hex(decNum))
oct2others(num)
10
11.Write a program that generates 4 terms of an
AP by providing initial and steps values to a
function that returns first four terms of the
series.
def retSeries(init, step):
return init, init+step, init+2*step,
init+3*step
ini= int(input("Enter initial value of th AP
series:"))
st= int(input("Enter step value of the AP
series:"))
print("Series with initial value", ini, "&step
value", st, "goes as:")
t1, t2, t3, t4=retSeries(ini, st)
print(t1,t2,t3,t4)
11
12.Write a program to display the size of a file
after removing EOL characters, leading and
trailing white spaces and blank lines.
myfile=open(r'F:\surplus.txt', "r")
str1=" "
size=0
tsize=0
while str1:
str1=myfile.readline()
tsize=tsize+len(str1)
size=size+len(str1.strip())
print("Size of file after removing all
Eol characters and blank lines:", size)
print("Total size of the file:", tsize)
myfile.close()
12
13. Write a program to display the size of a file
in bytes.
myfile=open(r'F:\surplus.txt', "r")
str=myfile.read()
size=len(str)
13
15.Write a program get roll numbers and marks
of the students of a class and store these details
in a file called “Marks.det”
count=int(input("How many students are there in the
class?"))
fileout=open("Marks.det", "w")
for i in range(count):
rollno=int(input("Rollno.:"))
name=input("Name")
marks=float(input("Marks"))
rec=str(rollno)+","+name+ ","+str(marks)+"\n"
fileout.write(rec)
fileout.close()
14
NATION PUBLIC SCHOOL
(B.S.R)
Session:- 2021-22
Computer Science Practical File
Name-
Class- XIITH (Commerce)
Submitted To:- Miss Tanu SHARMA
15