Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Informatics Practices project file:

Name: Shambhavi Shekhar Singh


Class: 11 ‘A’ Science
1. Program 1- Write a program to generate values from 1 to 10 and then remove all the odd numbers from the
list.
Source code-
num1=[]
for i in range(1,11):
num1.append(i)
print("Numbers from 1 to 10......\n",num1)
for j, i in enumerate(num1):
if(il-2%):
del num1 [j]
print("The values after removed odd numbers......\n",num1)
Output-
Numbers from 1 to 10.....
[109,8,7,6,5,4,3,2,1]
The values after removed odd numbers......
[10,8,6,4,2]
2. Program 2- Write a Program that generate a set of prime numbers and another set. of odd numbers. Display
the result of union, intersection, difference and symmetric difference operations.
Source code-
odd-set([x*1+2 for x in range(0,5)])
primes-set()) for i in range(2,10):
j=2
f=0
while j<i/2:
ifi%j==0:
f=1
j+=1 if f-0:
primes.add(i)
print("Odd Numbers: ", odd)
print("Prime Numbers: ", primes) print("Intersection:", odd.intersection(primes)) print("Difference: ",
odd.difference(primes)) print("Symmetric Difference:, odd.symmetric_difference(primes))
print("Union:", odd.union(primes))
Output-
Odd Numbers: (9,7,5,3,1)
Prime Numbers: (7,5,4,3,2). Union: (9,7,5,4,3,2,1) Difference: [9,1} Symmetric Difference: (9,4,2,1)
Intersection: (7,5,3)
3. Program 3- Write a program to accept a string and print the number of uppercase, lowercase, vowels,
consonants and spaces in the given string using Class.
Source code-
class String:
def __init__(self):
self.uppercase=0
self.lowercase=0
self.vowels-01
self.consonants=0
self.spaces=0 self.string="
def getstr(self):
self.string-str(input("Enter a String: "))
def count_upper(self): for ch in self.string:
if (ch.isupper()):
self.uppercase+=1
def count_lower(self):
for ch in self.string:
if (ch.islower()): selflowercase+=1
def count vowels(self):
for ch in self.string:
if (ch in ('A', 'a', 'e', E, T, T, 'o', 'O'. T. L.')): self.vowels+=1
def count consonants (self):
for ch in self.string: if (ch not in ('A', 'a', 'e', E, I, T, 'o', 'O, T, L')):
self.consonants+=1
def count_space(self): for ch in self.string:
if (ch===""):
self.spaces+=1
def execute(self):
self.count upper() self.count lower()
self.count vowels()
self.count_consonants()
self.count_space()
def display (self):
print("The given string contains...")
print("%d Uppercase letters"%self.uppercase) print("%d Lowercase letters"%self.lowercase).
print("%d Vowels"%self.vowels)
print("%d Consonants %self.consonants)
print("%d Spaces"%self.spaces)
S = String()
S.getstr()
S.execute()
S.display()
Output-
Enter a String: Welcome to Computer Science
The given string contains...
3 Uppercase letters
21 Lowercase letters
10 Vowels
17 Consonants
3 Spaces
4. Program 4- Write a program using functions to check whether a number is even or odd.
Source code-
defoddeven(a):
if (a0--2%):
return 1
else:
return 0
num= int(input("Enter a number: "))
if (oddeven(num)==1);
print("The given number is Even")
elif (oddeven(num)==0):
print("The given number is Odd")
Output-
Enter a number: 7 The given number is Odd
Enter a number: 6
The given number is Even
5. Program 5- Write a program to create a mirror of the given string. For example, "wel" = "lew".
Source code-
def rev(str1):
str2="
i-len(str1-(1
while i>=0:
str+2=str[i]
i=1
return str2
word=input("\n Enter a String:")
print("\n The Mirror image of the given string is:", rev(word))
Output-
Enter a String: school
The Mirror image of the given string is: loohcs
6. Program 6- Write a python program to calculate the area of a Triangle.
Source code-
a=5
b=6
c=7
a = float(input('Enter first side: '))
b = float(input('Enter second side: '))
c = float(input('Enter third side: '))
s = (a + b + c) / 2
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)
Output-
The area of the triangle is 14.70
7. Program 7- Write a python program to check if a number is odd or even.
Source code-
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))
Output
Enter a number: 12
12 is Even
OR
Enter a number: 13
13 is odd
8. Program 8- Write a python program to check leap year.
Source code-
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
else:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
Output:
2000 is a leap year
9. Program 9- Write a python program to check prime number.
Source code-
num = 407
if num > 1:
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")
else:
print(num,"is not a prime number")
Output-
407 is not a prime number
11 times 37 is 407
10. Program 10- Write a python program to display the multiplication table.
Source code-
num = 12
for i in range(1, 11):
print(num, 'x', i, '=', num*i)
Output-
12 × 1 = 12
12 × 2 = 24
12 × 3 = 36
12 × 4 = 48
12 × 5 = 60
12 × 6 = 72
12 × 7 = 84
12 × 8 = 94
12 × 9 = 108
12 × 10 = 120
11. Program 11- Write a python script to take input for a number check if the entered number is Armstrong or not.
Source code-
num = int(input(“Enter a number: “))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")
Output-
Enter a number: 663
663 is not an Armstrong number
OR
Enter a number: 407
407 is an Armstrong number
12. Program 12- Write a python program to find the largest and smallest number in a list.
Source code-

lst = []
num = int(input('How many numbers: '))
for n in range(num):
numbers = int(input('Enter number '))
lst.append(numbers)

print("Maximum element in the list is :", max(lst), "\nMinimum element in the list is :", min(lst))
Output-
How many numbers : 6
Enter number 25
Enter number 96
Enter number 32
Enter number 54
Enter number 74
Enter number 29
Maximum element in the list is : 96
Minumim element in the list is : 25
13. Program 13- Write a python program to find out the third largest number in a list.
Source code-

num = [2,3,7,4,5,6,10,11,120]

largest_num = num[0] second_largest_num = num[0] third_largest_num = num[0]

for i in num :

if i > largest_num :

third_largest_num = second_largest_num

second_largest_num = largest_num largest_num = i

elif i > second_largest_num : third_largest_num = second_largest_num second_largest_num = i

elif i > third_largest_num : third_largest_num = i

print("Third largest number of the list is {}".format(third_largest_num))

Output-

Third largest number is 10


14. Program 14- Write a python program to print the first ‘n’ multiples of a given number.

Source code-

n = int(input("Enter number: ")) print("First five multiples of", n, "are") print(n, n * 2, n * 3, n * 4, n * 5)


Output-
Enter number: 5

First five multiples of 5 are

5, 10, 15, 20, 25

15. Program 15- Create a dictionary to store the names of states and their capitals.

Source code-

states = dict()

n = int(input("How many states are there : ")) for i in range(n): state=input("Enter name of the state: ")

capital input("Enter name of the capital : ")


states [state] = capital

print("Created dictionary is :"states) temp = input("Enter the state to display capital : ")

print (states [temp])

Output- (For ex.)

How many states are there : 2

Enter name of the state : Gujrat

Enter name of the capital: Ahmedabad

Enter name of the state : Bihar

Enter name of the capital: Patna

Created dictionary is: {'Gujrat': 'Ahmedabad', 'Bihar': 'Patna'} Enter the state to display capital: Gujrat

Ahmedabad

The End.

You might also like