0% found this document useful (0 votes)
9 views11 pages

cs practical

Uploaded by

ishanbahuguna5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views11 pages

cs practical

Uploaded by

ishanbahuguna5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

1.

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:")

inc=float(input("Enter your height(in inches):"))

ft=inc//12

inc=inc%12

print("Hello I am",nm,", and my height is",ft,"feet and",inc,"inches.")

2.WAP to accept Principal, Time


and Rate. The program should display the Compound Interest
calculated using the following formula:
A=P(1+R/100)T
CI=A-P
a=float(input("Enter the Principal Amount:"))

b=int(input("Enter the Time Period(in years):"))

c=float(input("Enter the Rate of Interest:"))

A=a*(1+c/100)**b

Ci=A-a

print("The Compound Interest is:",Ci)

3. WAP to calculate the Radius of the sphere whose area(4πr2) is


entered by the user.
import math

a=float(input("Enter the area of the sphere:"))

r=math.sqrt(a/(4*math.pi))

print("The Radius of the sphere according to the area entered is",r)

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:"))

b=int(input("Enter the coefficient of the linear term:"))

c=int(input("Enter the constant term:"))

r1=((-b+(((b**2)-(4*a*c))**0.5))/2*a)

r2=((-b-(((b**2)-(4*a*c))**0.5))/2*a)

print("The Quadratic Equation is:",a,"x^2+",b,"x+",c)

print("The roots of the quadratic equation are:",r1,"and",r2)

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:"))

b=int(input("Enter the day of the year:"))

c=(30*(a-1))+b

print("Day of the year is:",c)

Page 2
6.WAP that accepts the number X and using
appropriate Menu perform the following
tasks:

a) Total number of digits in it.


d) Sum of all digits.

b) Reversed number.
e) New number Y, which contains LSD at
Hundreds place, total

c) Whether it is palindrome or not. number of digits at tens place


and MSD at ones place.

d=0

a=int(input("Enter a number:"))

b=str(a)

print("Total number of digits is:",len(b))

print("The reversed number is:",b[::-1])

if b==b[::-1]:

print("The number is a palindrome:")

else:

print("The number is not a palindrome:")

for i in range(len(b)):

d+=int(b[i])

print("The sum of digits is:",d)

print("New number is-->",100*int(b[-1])+10*int(len(b))+int(b[0]))

7. WAP that accepts some numbers and display the following data. The process should continue
when the user enters 0:

a. Sum of all the even number entered.

b. Total number of odd numbers entered.

c. Average of the numbers entered.

d. Largest and smallest number entered.

e. All the numbers that ends with 4.

l=[]
print("The sum of even numbers
l1=[] is:",se)

se=count=0 print("The count of odd numbers


is:",count)
while True:
print("The average of the numbers
entered is:",sum(l)/int(len(l)))

print("The largest number


is",max(l),"and the smallest number
is",min(l))
a=input("Enter any number:")

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))

8. WAP that accepts a


number and displays its factorial in the following format.
Page 3
Suppose user enters 5, the output should be:

5 ! = 5 X 4 X 3 X 2 X 1 = 120
b=1

c=""

a=int(input("Enter any number:"))

for i in range(a,0,-1):

b*=i

if c:

c+=f" X {i}"

else:

c=str(i)

print(f"{a}! = {c} = {b}")

9. WAP that displays the following pattern


for i in range(4):

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()

10. WAP that accepts a string


and capitalize every alternate
character. The program should display the
original and new strings.

b=""

a=input("Enter any string:")

print("The original string is:",a)

for i in range(len(a)):
if i%2==0:

b+=a[i].upper()

else:

b+=a[i].lower()

print("The modified string is:",b)

11. WAP that accepts emailIDs of n users. Create two lists that stores
user ID and domain names separately Page 5

l=[]

l1=[]

n=int(input("Enter how many entries you want to do:"))

for i in range(n):

a=input("Enter the email id:")

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

a=input("Enter any line:")

b=a.split()

for i in b:

print(i)

13. WAP to accept an address containing pincode. Extract the


pincode from the address and display them. The process should
Page 6
continue till the user presses ‘Y’ or ‘y’.
while True:
a=input("Enter the address: with 6 digit pincode separated with space:")

b=a.split()

pin=None

for i in b:

if i.isdigit() and len(i)==6:

pin=i

break

if pin:

print("The pincode is.",pin)

else:

print("The pincode is not found")

p=input("Do you want to continue?(Y/y to continue):")

if p in "yY":

continue

else:

break

14. WAP that


accepts a
string.
Extract all
the digits
from the string.
If there are digits, display:
a. Sum of all the digits entered.
b. Print:
i. Original string
ii. Digits
iii. Sum of digits
If there are no digits,

a. Print <original string > has no digits.


l1=[]
a=input("Enter a string:")

print("The original string is:",a)


for i in a:
if i.isdigit():
l1.append(int(i))
if len(l1)==0:
print("No digits are there in the string:")
else:
print("The digits are:",l1)
print("The sum of digits is:",sum(l1))

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)

print("The new lists after performing left shift are:",a[:c],a[c:])

19.WAP to accept a list of numbers & perform right shift.


a=eval(input("Enter a list of numbers:")) Page 8
b=int(input("Enter the value from where you want to perform left shift:"))
c=a.index(b)
print("The new lists after performing left shift are:",a[:c+1],a[c+1:])
20. WAP to accept the nested tuple and print mean of each nested
tuple. The program must then display the mean of each mean
calculated.
c=0

d=0

a=eval(input("Enter a nested tuple:"))

for i in range(len(a)):

b=sum(a[i])

print("The mean of tuple",a[i],"is",b/len(a[i]))

c+=b

d+=len(a[i])

print("The mean value of the means of nested tuple is:",c/d)

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}

for key,value in d1.items():

d2[value]=key

print("The original dictionary is:",d1)

print("The new dictionary is:",d2)

23.WAP to accept the string and display total number of


occurrences of each character.
a=input("Enter a string:")
for i in a:
print(f"The character {i} comes
{a.count(i)} times")

24.A dictionary D1 has values in the


form of list of numbers write a
program to create a new dictionary D2 having same keys as D1
one but values are as sum of list of values.
a=eval(input("Enter a dictionary:"))
d={}
for i in a:
c=sum(a[i])
d[i]=c
print("The new dictionary
is:",d)

25. WAP to perform sorting on list of numbers.


l=eval(input("Enter a list of numbers:"))
print("The sorted list is:",sorted(l))

Page 10

You might also like