vertopal.com_C_S_practicals (2)
vertopal.com_C_S_practicals (2)
elif n == 2:
side=float(input("enter side length of square in cm: "))
squarea=(side*side,"cm2")
print(squarea)
break
else:
radi=float(input("enter the radius of circle in cm: "))
circarea=((3.14*(radi*radi)),"cm2")
print(circarea)
break
num=int(num)
if sum==num:
print("given number is an armstrong number")
else:
print("given number is not an armstrong number")
sum=0
for i in (num):
i=int(i)
sum+=i
sum=1
n=2
while n<=exp:
x=(base**n)
sum+=x
n+=1
import math
print("wap for second series")
exp=int(input("enter the value of the exponent upto which you want
series to continue: "))
base=int(input("enter the value of the number which you want to
exponentiate: "))
sum=0
n=2
z=3
while exp>=n:
x=(base)
y=(base**n)
w=((base)-(base**n)/(math.factorial(z)))
sum+=w
n+=1
z+=2
#1 A
#1 2 B C
#1 2 3 D E F
#1 2 3 4 G H I
J
for i in (s):
if len(i)>maxlen:
maxlen=len(i)
longestsub=i
countu=0
countl=0
countd=0
for i in string:
if i.isupper()==True:
countu+=1
elif i.islower()==True:
countl+=1
elif i.isdigit()==True:
countd+=1
print("count of uppercase is: ", countu)
print("count of lowercase is: ", countl)
print("count of digit is: ", countd)
L1=[]
L2=[]
for i in L:
if i > (0):
L1.append(i)
if ((i)%(2)) != (0):
L2.append(i)
largele=max(L)
print(largele,"is the largest element")
L=[]
n=int(input("enter the number of elements in your list: "))
for i in range(n):
ele=int(input("enter the element: "))
L.append(ele)
position=L[i]
found = False
for i in range(len(L)):
if L[i] == x:
print(f"{x} is the element required and lies at index: {i}")
found = True
break # Stop searching once the element is found
for i in range(r):
L1=[]
for j in range(c):
ele=int(input("enter the element: "))
L1.append(ele)
L.append(L1)
for i in range(r):
for j in range(c):
print(L[i][j],end=" ")
print()
for i in range(r):
rs=0
for j in range(c):
rs+=L[i][j]
print("the sum of each row is: ", rs)
for i in range(c):
cs=0
for j in range(r):
cs+=L[j][i]
print("the sum of each column is: ", cs)
L=[]
r=int(input("enter the number of rows required: "))
c=int(input("enter the number of columns required: "))
for i in range(r):
L1=[]
for j in range(c):
ele=int(input("enter the element: "))
L1.append(ele)
L.append(L1)
for i in range(r):
for j in range(c):
print(L[i][j], end=" ")
print()
print("the above is the original matrix")
for i in range(c):
for j in range(r):
print(L[j][i], end=" ")
print()
print("the above is the required transpose!")
L = []
n = int(input("enter the number of students you would like to record:
"))
for i in range(n):
l1 = []
rollno = int(input("enter the roll number of student (no 2
students may have the same roll number): "))
name = input("enter the name of student: ")
stream = input("enter the stream of student: ")
marks = int(input("enter the mark of student (out of 100): "))
l1 = [rollno, name, stream, marks]
L.append(l1)
if code == 1:
ndash = int(input("enter the number of students you would like to
add: "))
for i in range(ndash):
l1 = []
rollno = int(input("enter the roll number of student: "))
name = input("enter the name of student: ")
stream = input("enter the stream of student: ")
marks = int(input("enter the mark of student (out of 100): "))
l1 = [rollno, name, stream, marks]
L.append(l1)
print(L)
print("list has been updated")
elif code == 2:
found = False # Flag to check if any student has distinction
for i in L:
if i[3] >= 85:
print(i[1])
found = True
if not found:
print("no students have distinction")
else:
print("the above are the students with distinction")
elif code == 3:
rollout = int(input("enter the roll number of student to be
expelled: "))
found=False
for i in L:
if i[0] == rollout:
L.remove(i)
found= True
break
if found:
print("the student has been deleted")
else:
print("no such roll number found")
print(L)
elif code == 4:
rollin = int(input("enter the rollnumber whose record needs to be
updated"))
namenew = input("enter the new name of student: ")
streamnew = input("enter the new stream: ")
marksnew = int(input("enter the marks need to be updated: "))
for i in L:
if i[0] == rollin:
i[1] = namenew
i[2] = streamnew
i[3] = marksnew
elif code == 5:
print(L)
else:
print("visit again")
for i in range(n):
fibolist.append(a)
c=a+b
a=b
b=c
print(tuple(fibolist))
#20.)WAP to create a tuple of names and display only those names whose
second character is ‘A’ or ‘a’.
#21.)wap to create nested tuple and find the largest element in the
tuple
tuple1 = tuple(L)
l = []
n=int(input("enter the number of elements you require in nested tuple:
"))
for i in range(n):
fac=int(input("enter the factor: "))
l.append(fac)
tuple2= tuple(l)
maxele=0
for i in tuple0:
if type(i)==tuple:
for j in i:
if j > maxele:
maxele=j
elif i> maxele:
maxele=i
}
for i in range(n):
emp=input("enter name of employee: ")
sal=int(input("enter salary of employee (aed/month): "))
dict1[emp]=sal
for i in range(n):
subj=input("enter the subject of teacher: ")
name=input("enter the name of teacher: ")
dict2[subj]=name
print(dict2,"is the original dictionary")
dict2["English"]=modified
dictnum={
"0":"Zero",
"1":"One",
"2":"Two",
"3":"Three",
"4":"Four",
"5":"Five",
"6":"Six",
"7":"Seven",
"8":"Eight",
"9":"Nine"
}
for i in num:
if i in dictnum:
print(dictnum[i], end=" ")
# Display the Name and Phone number for all your friends:DONE
# Add a new key-value pair in this dictionary and display the modified
dictionary: DONE
friend = {
for i in range(n):
name = input("enter the name of your friend: ")
number = int(input("enter the number of your friend: "))
friend[name] = number
friend["tokyo"] = (4)
del friend["tokyo"]
friend[mod]=numod
sorteddict=dict(sorted(friend.items()))
print("the sorted dictionary is: ", sorteddict)