[go: up one dir, main page]

0% found this document useful (0 votes)
18 views12 pages

Final Final Prac

Uploaded by

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

Final Final Prac

Uploaded by

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

COMPUTER SCIENCE PRACTICAL

-GURTEJ SINGH BEDI

PYTHON BASICS:
Q) WAP TO CALCULATE BMI OF A PERSON

A) a=int(input("What is your weight in kg?"))

b=float(input("What is your height in m?"))

c=a/(b*b)

print("Your body mass index=",c)

OUTPUT:

Q) WAP TO CONVERT FARHENHEIT INTO CELCIUS AND VICE VERSA

A) print(“1. Fahrenheit to Celsius”)

print(“2. Celsius to Fahrenheit”)

choice=int(input("enter your choice"))

if choice==1:

f=float(input("enter Fahrenheit temperature"))

c=(f-32)/1.8
print("Converted temperature”, c)

if choice==2:

c=float(input("enter celcius temperature"))

f=9/5*c+32

print("converted temperature", f)

if choice<1 or choice>2:

print("Only 1 or 2 AVAILABLE")

OUTPUT

Q) WAP to find the area of circle

A) n=int(input(“ENTER THE RADIUS OF THE CIRCLE”))

a=3.14*n*n #area=pir2

print(“Area of the circle is”,a)

OUTPUT
Q) WAP TO CHECK FACTORS

A) n1=int(input("Enter 1st number"))

n2=int(input("Enter 2nd number"))

if n2%n1==0:

print(n1,"is a factor of",n2)

if n2%n1!=0:

c=n2/n1

print(c, "Not a factor")

OUTPUT

CONDITIONAL STATEMENTS

Q) WAP TO SHOW GRADES:

A) average=int(input("Enter your average mark:"))

if average>=80:

print("NERD")

elif average>=70 and average<80:

print("B grade")

elif average>=60 and average<70:


print("D Grade")

elif average>=50 and average<60:

print("E GRADE")

else:

print("F Grade")

OUTPUT

Q) WAP TO FIND THE FACTORIAL OF A NUMBER:

A)

fact=1

i=1

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

while i<=n:

fact=fact*i

i=i+1

print(fact)

OUTPUT
Q) WAP TO MAKE FIBONACCI SERIES:

A) a=1

b=1

n=int(input("Enter number upto which series must be created"))

print(a)

print(b)

c=a+b

while c<=n:

print(c)

a,b=b,c

c=a+b

OUTPUT
Q) WAP TO CHECK IF THE YEAR IS A LEAP YEAR OR NOT

A)

n=int(input("enter year in four digit form"))

if n%100==0:

if n%400==0:

print("leap year")

else:

print("not a leap year")

elif n%4==0:

print("leap year")

else:

print("not a leap year")

OUTPUT
Q) WAP A PROGRAM TO FIND THE SUM OF GIVEN NATURAL NUMBERS:

A) n=int(input("How many numbers :"))

i=1

s=0

while i<=n:

s=s+i

i=i+1

print("sum of above numbers is",s)

OUTPUT

Q) WAP TO CHECK IF THE GIVEN NUMBER IS PRIME OR NOT:

A)

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

flag=0 #it is prime

for i in range(2,n):

if n%i==0:

flag=1

break
if flag==0:

print("prime")

else:

print("Not prime")

OUTPUT

STRINGS

Q) WAP TO CREATE A MATRIX IN STRING

A) m=int(input("Enter number of rows"))

n=int(input("Enter number of columns"))

M=[[0 for col in range(m)]

for row in range(n)

for i in range(m):

print("Enter data for row",i+1)

for j in range(n):

M[i][j]=int(input())

print("The matrix is now \n")

for i in range(m):
for j in range(n):

print(M[i][j],end="\t")

print()

OUTPUT
Q) WAP TO CREATE PALINDROME IN STRING

A) s=input("Enter a string :")

s1=s[::-1]

if s==s1:

print("Palindrome")

else:

print("Not a palindrome")

OUTPUT

LIST

Q) WAP TO ADD ELEMENTS IN A LIST:

A) list1=[]

n=int(input("Enter number of elements: "))

for i in range(n):

a=int(input("Enter the element"))

list1.append(a)

i=i+1

print("items in the list are: ")

print(list1)
OUTPUT

Q) WAP TO COUNT TOTAL NUMBER OF POSITIVE AND NEGATIVE ELEMENTS IN A


LIST

A) l=[] #original list

positivelist=[]

negativelist=[]

n=int(input("Enter how many elements:"))

for i in range(n):

num=int(input("Enter element to add"))

l.append(num)

for i in l:

if i>=0:

positivelist.append(i)

if i<0:

negativelist.append(i)

print("Total positive numbers",len(positivelist))

print("Total negative numbers",len(negativelist))


OUTPUT

THANK YOU

You might also like