0% found this document useful (0 votes)
2 views

Practical 2

The document contains a series of practical Python programming exercises, including displaying text, performing mathematical operations, and manipulating data structures such as lists and tuples. Each practical section includes specific tasks with example code and expected outputs. The document is authored by Mehtre A. N.

Uploaded by

Ankush Mehtre
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)
2 views

Practical 2

The document contains a series of practical Python programming exercises, including displaying text, performing mathematical operations, and manipulating data structures such as lists and tuples. Each practical section includes specific tasks with example code and expected outputs. The document is authored by Mehtre A. N.

Uploaded by

Ankush Mehtre
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/ 7

Practical 2

1) Write a Python program to display “MSBTE” using Script Mode

print("MSBTE")

Output

2) Write a Python program to display your name using Interactive Mode

>>>print("Ankush Mehtre")

Output

Code Executed by Mehtre A . N


Practical 3
1) Write a program to convert U S Dollars to INR

USD=float(input("enter the dollers : "))

INR=USD*87.64

print("INR = ",INR)

Output

2) Write a program to find squire root of a number


import math

num=float(input("enter a number : "))


square=math.sqrt(num)
print("square root of given number is : ",square)
Output

3) Write a program to find the area of Rectangle


leanth=float(input("enter leanth of rectangle : "))
breadth=float(input("enter breadth of rectangle : "))
area=leanth*breadth
print("area of rectangle is : ",area)
Output

Code Executed by Mehtre A . N


Practical 4
1) Write a program to check whether a number is even or odd
num=int(input("enter a number = "))
if(num%2==0):
print("entered number is even ")
else:
print("entered number is odd")
Output

2) Write a program to find out absolute value of an input number


num=int(input("enter a number = "))
print("absolute number is = ",abs(num))
Output

3) Write a program to check the largest number among the three numbers
num1=float(input("enter a number = "))
num2=float(input("enter a number = "))
num3=float(input("enter a number = "))
if(num1>num2 and num1>num3):
print(num1,"is greater")
elif(num2>num1 and num2>num3):
print(num2,"is greater")
else:
print(num3,"is greater")
Output

4) Write a program to check if the input year is a leap year of not


year=int(input("enter year : "))
if(year%4==0):
print(year,"is leap year")
else:
print(year,"is not leap year")
Output

Code Executed by Mehtre A . N


Practical 5
1) Write a Python program to print all even numbers between 1 to 100 using while
loop.
i=1
while i<=100:
print(i)
i+=1
Output

2) Write a Python program to find the sum of first 10 natural numbers using for loop.
sum=0
i=1
while i<=10:
sum=sum+i
i+=1
print("sum of first 10 natural numbers = ",sum)
Output

3) Write a Python program to print Fibonacci series.


limit=int(input("enter the number : "))
a=0
b=1
c=0
while c<=limit:
print(c)
a=b

Code Executed by Mehtre A . N


b=c
c=a+b
Output

4) Write a Python program to calculate factorial of a number


num=int(input("enter the number : "))
fact=1
for i in range(1,num+1):
fact=fact*i
print(fact)
Output

Code Executed by Mehtre A . N


Practical 6
1) Write a Python program to sum all the items in a list.
l=[10,20,30,40,50]
sum=0
for i in range(0,len(l)):
sum+=l[i]
print("sum of list is : ",sum)
Output

2) Write a Python program to multiplies all the items in a list.


l=[10,20,30,40,50]
mul=0
for i in range(0,len(l)):
mul=mul*l[i]
print("mul of list is : ",mul)
Output

3) Write a Python program to get the largest number from a list.


l=[10,20,30,40,50]
print("largest number in list is : ",max(l))
Output

4) Write a Python program to get the smallest number from a list.


l=[10,20,30,40,50]
print("smallest number in list is : ",min(l))
Output

5) Write a Python program to reverse a list.


l=[10,20,30,40,50]
l.reverse()
print("reversed list is = ",l)
Output

Code Executed by Mehtre A . N


Practical 7
1) Create a tuple and find the minimum and maximum number from it.
tuple=(10,20,80,90,10,200,70,40,4000,5)
maximum=max(tuple)
minimum=min(tuple)
print("maximum number in tuple is : ",maximum)
print("minimum number in tuple is : ",minimum)
Output

2) Write a Python program to find the repeated items of a tuple.


from collections import Counter
def find_repeated_items(input_tuple):
item_counts = Counter(input_tuple)
repeated_items = [item for item, count in item_counts.items() if count > 1]
return repeated_items

input_tuple = (1, 2, 3, 4, 5, 2, 3,5,1,9,7,2,1,4,6,7,8,2,3)


repeated = find_repeated_items(input_tuple)
print("Repeated items:", repeated)
Output

Code Executed by Mehtre A . N

You might also like