cs practical
cs practical
WAP to accept your name and height (in inches), convert it into feet
and inches and display it in the following format:
Hello I am <nm>, and my height is <ft>feet and <inc> inches.
nm=input("Enter your name:")
ft=inc//12
inc=inc%12
A=a*(1+c/100)**b
Ci=A-a
r=math.sqrt(a/(4*math.pi))
Page 1
4.WAP to accept 3 coefficients of a quadratic equation and display its
roots.
Suppose the equation is : ax2+bx+c, where a, b and c is entered by the
user, then the roots of the equation is calculated as:
Root1=(-b+√b2-4ac)/2a
Root2=(-b-√b2-4ac)/2a
a=int(input("Enter the leading coefficient of the quadratic equation:"))
r1=((-b+(((b**2)-(4*a*c))**0.5))/2*a)
r2=((-b-(((b**2)-(4*a*c))**0.5))/2*a)
5. WAP to take two inputs, day, and month from the user. The program
should calculate which day of the year the given date is. Take days for
all the month as 30 for simplicity. For eg., if the user enters day=3 and
month=2, then the output
must be: Day of the year: 33
a=int(input("Enter the
month of the year:"))
c=(30*(a-1))+b
Page 2
6.WAP that accepts the number X and using
appropriate Menu perform the following
tasks:
b) Reversed number.
e) New number Y, which contains LSD at
Hundreds place, total
d=0
a=int(input("Enter a number:"))
b=str(a)
if b==b[::-1]:
else:
for i in range(len(b)):
d+=int(b[i])
7. WAP that accepts some numbers and display the following data. The process should continue
when the user enters 0:
l=[]
print("The sum of even numbers
l1=[] is:",se)
if a=="0":
break
if int(a)%2==0:
se+=int(a)
else:
count+=1
l.append(int(a))
if int(a)%10==4:
l1.append(int(a))
5 ! = 5 X 4 X 3 X 2 X 1 = 120
b=1
c=""
for i in range(a,0,-1):
b*=i
if c:
c+=f" X {i}"
else:
c=str(i)
for j in range(i+1):
print("*",end=" ")
print()
A=65
for i in range(4):
for j in range(i+1):
print(chr(A),end=" ")
A+=1
print()
a=1
for i in range(4):
for j in range(i+1):
print(a,end=" ")
a+=1
print()
a=1
for i in range(4):
for j in range(i+1):
Page 4
print(a,end=" ")
a+=1
print()
a=65
for i in range(4):
for j in range(i+1):
print(chr(a),end=" ")
a+=1
print()
for i in range(4):
a=65
for j in range(i+1):
print(chr(a),end=" ")
a+=1
print()
b=""
for i in range(len(a)):
if i%2==0:
b+=a[i].upper()
else:
b+=a[i].lower()
11. WAP that accepts emailIDs of n users. Create two lists that stores
user ID and domain names separately Page 5
l=[]
l1=[]
for i in range(n):
b=a[:a.index('@')]
l.append(b)
c=a[a.index('@')+1:a.index('.')]
l1.append(c)
print(l)
print(l1)
12. WAP that accept a line and display each word on separate lines
b=a.split()
for i in b:
print(i)
b=a.split()
pin=None
for i in b:
pin=i
break
if pin:
else:
if p in "yY":
continue
else:
break
15. WAP that accepts a list & determine whether the no is present in
1st half or the 2nd half of the list. Page 7
a=eval(input("Enter a list:"))
b=int(input("Enter a number:"))
if b in a[:len(a)//2]:
print("The number is present in the
first half of the list")
else:
print("The number is present in the
second half of the list")
16. WAP that accepts a list & interchanges the 1st half elements with
the 2nd half elements of the list.
a=eval(input("Enter a list:"))
b=len(a)
a=a[b//2::]+a[:b//2]
print("The new list is:",a)
17. WAP to create a list of strings. The list must create a new list same
as he first with its 1st character removed.
a=eval(input("Enter a list of strings:"))
a.pop(0)
print("The new list is:",a)
18. WAP to
accept a
list of
numbers
& perform
left shift.
a=eval(input("Enter a list of numbers:"))
b=int(input("Enter the value from where you want to perform left shift:"))
c=a.index(b)
d=0
for i in range(len(a)):
b=sum(a[i])
c+=b
d+=len(a[i])
21.
WAP
to
accept roll number, name and marks of n students. Store the data in the form
of Dictionary in which keys are roll number and values are in the form of list of
name and marks. The program must then ask the roll number and display its
corresponding marks.
n=int(input("Enter the total entries you want to enter:"))
d={}
for i in range(n):
a=int(input("Enter the roll number:"))
b=input("Enter the name:")
c=input("Enter the marks obtained:")
d[a]=[b,c]
print(d)
f=int(input("Enter the roll number whose data you want to see:"))
if f in d:
print(f"The name of the student is {d[f][0]} and marks obtained are {d[f][1]}")
Page 9
22. Given a dictionary:
X={ k1 : v1 , k2 : v2 , k3 : v3 }
Create another dictionary with opposite mapping. Ie.
Y={ v1 : k1 , v2 : k2 , v3 : k3 }
d2={}
d1={"a":1,"b":2,"c":3}
d2[value]=key
Page 10