Class 11 PRACTICAL FILE

Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 11

PRACTICAL FILE- COMPUTER SCIENCE (083)

LIST OF PRACTICAL (2022-23) CLASS-XI


Programming Language : Python
S.
No.
NAME OF PRACTICAL
1 Write a simple Python program to print a message.
Ans-M1
# This program prints Hello, world!

print('Hello, world!')
output- Hello, world!
2 Write a program to find the sum of two numbers
Ans- M1
#This program adds two numbers

num1 = 1.5
num2 = 6.3

# Add two numbers


sum = num1 + num2

# Display the sum


print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))

M2
#Store input numbers
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')

# Add two numbers


sum = float(num1) + float(num2)

# Display the sum


print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))

M3
print('The sum is %.1f ' %(float(input('Enter first number: ')) + float(input('Enter second number:
'))))
3 Write a program to calculate average of n numbers.
Ans-M1
n = int(input("Enter number"))
sum = 0
# loop from 1 to n
for num in range(1, n + 1, 1):
sum = sum + num
print("Sum of first ", n, "numbers is: ", sum)
average = sum / n
print("Average of ", n, "numbers is: ", average)

M2
n = 10
res = sum(range(1, n + 1))
print("Sum of first ", n, "numbers is: ", res)

# Output Sum of first 10 numbers is: 55


M3
n = 20
# formula to calculate sum
res = n * (n + 1) / 2
print('sum of first', n, 'numbers is:', res)
# Output sum of first 20 numbers is: 210.0

# formula to calculate average


average = (n * (n + 1) / 2) / n
print('Average of first', n, 'numbers is:', average)
# Output Average of 20 numbers is: 10.5
4 Write a program to find greater number.

Ans-M1
# Python program to find the largest number among the three input numbers

# change the values of num1, num2 and num3


# for a different result
num1 = 10
num2 = 14
num3 = 12

# uncomment following lines to take three numbers from user


#num1 = float(input("Enter first number: "))
#num2 = float(input("Enter second number: "))
#num3 = float(input("Enter third number: "))

if (num1 >= num2) and (num1 >= num3):


largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3

print("The largest number is", largest)

Write a program to find the greatest number among three numbers.


Ans-
# Python program to find the largest number among the three input numbers

# change the values of num1, num2 and num3


# for a different result
num1 = 10
num2 = 14
5 num3 = 12

# uncomment following lines to take three numbers from user


#num1 = float(input("Enter first number: "))
#num2 = float(input("Enter second number: "))
#num3 = float(input("Enter third number: "))

if (num1 >= num2) and (num1 >= num3):


largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3

print("The largest number is", largest)

6 Write a program to check a number whether it is even or odd.


Ans- M1
um = int(input("Enter a Number:"))
if num % 2 == 0:
print("Given number is Even")
else:
print("Given number is Odd")
M2
num = int(input("Enter the number"))
print("number is Even") if num%2 == 0 else print("number is Odd")

7 Write a python program that accepts radius of a circle and prints its area.
Ans- M1
r = float(input("Enter radius of circle: "))
a = 3.14159 * r * r
print("Area of circle =", a)

8 Write a program in python to check a number whether it is prime or not.


Ans-

num = int(input('entre the no.'))


# If given number is greater than 1
if num > 1:
# Iterate from 2 to n / 2
for i in range(2, int(num/2)+1):
# If num is divisible by any number between
# 2 and n / 2, it is not prime
if (num % i) == 0:
print(num, "is not a prime number")
break
else:
print(num, "is a prime number")
else:
print(num, "is not a prime number")

9 Write a program to check a year whether it is leap year or not.


Prog.M1

year = int(input('Enter year : '))

if (year%4 == 0 and year%100 != 0) or (year%400 == 0) :


print(year, "is a leap year.")
else :
print(year, "is not a leap year.")

M2
# Default function to implement conditions to check leap year
def CheckLeap(Year):
# Checking if the given year is leap year
if((Year % 400 == 0) or
(Year % 100 != 0) and
(Year % 4 == 0)):
print("Given Year is a leap Year");
# Else it is not a leap year
else:
print ("Given Year is not a leap Year")
# Taking an input year from user
Year = int(input("Enter the number: "))
# Printing result
CheckLeap(Year)
10 Write a program in python to convert °C to °F and vice versa.
Prog.M1
celsius = int(input("enter the no."))

# Converting the temperature to


# fehrenheit using the above
# mentioned formula
fahrenheit = (celsius * 1.8) + 32

# printing the result


print('%.2f Celsius is equivalent to: %.2f Fahrenheit' %(celsius, fahrenheit))

Write a program to check a number whether it is palindrome or not.


11 Ans-
num1=int(input("enter any number"))
num2=num1
rev=0
while num1!=0:
rem=num1%10
rev=rev*10+rem
num1=num1//10
if num2==rev:
print(num2,"is a palindrome number")
else:
print(num2,"is not a palindrome number")
12 Write a program to calculate the factorial of an integer.
Prog.
n=int(input("Enter any number"))
fac=1
for i in range(1,n+1):
fac=fac*i
print("Factorial of ",n,"is",fac)

Write a program to check if a string is palindrome or not.


Ans-
def isPalindrome(str):

# Run loop from 0 to len/2


for i in range(0, int(len(str)/2)):
if str[i] != str[len(str)-i-1]:
return False
return True

# main function
s = input("enter the string")
ans = isPalindrome(s)

if (ans):
print("Yes")
else:
print("No")
13 Write a program to check a number whether it is perfect number or not.
Ans-
n = int(input("Enter any number: "))
sum1 = 0
for i in range(1, n):
if(n % i == 0):
sum1 = sum1 + i
if (sum1==n):
print("The number is a Perfect number!")
else:
print("The number is not a Perfect number!")
14 Write a program to check a number whether it is armstrong number or not.
Ans-
def is_armstrong(num):
num_str = str(num)
n = len(num_str)
sum = 0
for digit in num_str:
sum += int(digit)**n
if sum == num:
return True
else:
return False
num=int(input("Enter the no."))
print(is_armstrong(num))
15 Write a program to calculate simple interest.
Ans
def simple_interest(p,r,t):
si = (p * r * t)/100
return si

p=int(input("Enter principal amount"))


r=int(input("Enter rate of interest"))
t=int(input("Enter time period"))

print('The Simple Interest is', simple_interest(p, r, t))


16 Write a program to calculate compound interest.
Ans-
# Python program to find compound interest

p = float(input("Enter the principle amount : "))


r = float(input("Enter the rate of interest : "))
t = float(input("Enter the time in the years: "))

# calculating compound interest


ci = p * (pow((1 + r / 100), t))

# printing the values


print("Principle amount : ", p)
print("Interest rate : ", r)
print("Time in years : ", t)
print("compound Interest : ", ci)

17 Write a program to swap two numbers.


Ans-
# Python program to demonstrate
# swapping of two variables

x = 10
y = 50

# Swapping of two variables


# Using third variable
temp = x
x=y
y = temp

print("Value of x:", x)
print("Value of y:", y)
18 Write a program to display ASCII code of a character and vice versa.
Ans
# Program to find the ASCII value of the given character
c =input("Enter any character: ")
print("The ASCII value of '" + c + "' is", ord(c))
20 Write a program that reads a string and print its statistics like : Number of Uppercase letters, Number of
lowercase letters, Number of alphabets, Number of digits, Number of symbols.
Ans-

st=input("enter any string")


u=l=a=d=s=0
for i in st:
if i.isalpha():
a+=1
if i.isupper():
u=u+1
else:
l=l+1
if i.isdigit():
d+=1
else:
s+=1
print("No. of alphabets",a)
print("No. of uppercase letters",u)
print("No. of lowercase letters",l)
print("No. of digits",d)
print("No. of symbols",s)
21 Write a python program to print fibonacci series.
Ans
n = int(input("enter the number:"))
num1 = 0
num2 = 1
next_number = num2
count = 1

while count <= n:


print(next_number, end=" ")
count += 1
num1, num2 = num2, next_number
next_number = num1 + num2
print()
22 Write the code using loop to display the following
pattern:

B
*
*
* *
A * *
* * *
* * * *
Ans * * *
n=4
* * * *
for i in range(0, n):
for j in range(0, i+1): * * * * *
print("*", end=" ")
Ans
print()
n=5;i=0
while(i<=n):
print(" " * (n - i) +"*" * i)
i+=1

1
*
2 2
C D * *
3 3 3 * * *
4 4 4 4 * * * *
Ans- * * * * *

Ans-
for i in range(1,6):
n=5;i=0
for j in range(1,i+1): while(i<=n):
print(j,end=" ") print(" " * (n - i) +" *" * i)
print() i+=1

1
F
1 2 F
E
1 2 3
1 2 3 4
1 2 3 4 5
Ans-

for i in range(1,6):
for j in range(1,i+1):
print(j,end=" ")
print()

A 1
B C 2 3
G H
D E F 4 5 6
G H I J 7 8 9 10
Ans-
for i in range (65,70):
# inner loop
for j in range(65,i+1):
print(chr(j),end=" ")
print()

A 10 9 8 7
BB 6 5 4
I J
C CC 3 2
D D DD 1
E E E E E
Ans-
for i in range (65,70):
# inner loop
for j in range(65,i+1):
print(chr(i),end="")
print()

23 Write a python program for the given expression: 1+x+x^2+x^3+.................+x^n

Write a python program for the given expression:


24

25 Write a program in python to find largest and smallest number in a list.


Ans-
# list of numbers
list1 = [10, 20, 1, 45, 99]

# printing the minimum element


print("Smallest element is:", min(list1))
print("largest element is:", max(list1))
26 Write a program to compute HCF and LCM of two numbers
Ans
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))

HCF = 1

for i in range(2,a+1):
if(a%i==0 and b%i==0):
HCF = i
print("HCF of the two numbers is: ",HCF)
LCM = int((a*b)/(HCF))
print("LCM of the two numbers is: ",LCM)
27 Write a program to compare two strings.
Ans
str1 = input("Enter the first String: ")

str2 = input("Enter the second String: ")

if str1 == str2:

print ("First and second strings are equal and same")

else:

print ("First and second strings are not same")


29 Write the program for linear search.
Create a dictionary with the roll number, name and marks of n students in a class and display the
30 names of students who have scored marks above 75.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy