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

dspoutputs

Uploaded by

Neha Vengurlekar
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)
17 views

dspoutputs

Uploaded by

Neha Vengurlekar
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/ 13

PRACTICAL NO 1

1) Print the version of Python.


Ans: import sys
print(sys.version)
3.9.4

2) Write steps to be followed to load Python interpreter in windows.


Ans :
step 1: Press start button
Step 2: click all programs find python 3.9.5 the python command line
Step 3: Python command prompt contains an opening msg
Step 4: to exit from the command line of python press (ctrl Z)followed by ctrl enter

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


>>> name = "Neha"
>>> print("My name is " + name)
#OUTPUT: My Name is Neha

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


>>> name = "MSBTE"
>>> print( name)
#OUTPUT: MSBTE
PRACTICAL NO 2

1.Write a program to convert U.S. dollars to Indian rupees.


Ans: usd = float(input("Enter currency in USD: "))
inr = usd * 81.58
print("The currency in INR is",round(inr,2))
# OUTPUT
# Enter currency in USD: 44
# The currency in INR is 3589.52

2.Write a program to convert bits to Megabytes, Gigabytes and Terabytes


def convert_bytes(bytes_number): tags = [ "Byte", "Kilobyte",
"Megabyte", "Gigabyte", "Terabyte" ] i = 0 double_bytes = bytes_number
while (i < len(tags) and bytes_number >= 1024): double_bytes =
bytes_number / 1024.0 i = i + 1
bytes_number = bytes_number / 1024 return
str(round(double_bytes, 2)) + " " + tags[i]
print(convert_bytes(4896587482345))
print(convert_bytes(9876524362))
print(convert_bytes(10248000))
# OUTPUT
# 4.45 Terabyte
# 9.2 Gigabyte
# 9.77 Megabyte
3.Write a program to find the square root of a number
# import math
# a=math.sqrt(9)
# print(a)
# # OUTPUT
# # 3.0

4.Write a program to find the area of Rectangle


# l = float(input('Enter the length of a Rectangle: '))
# b = float(input('Enter the breadth of a Rectangle: '))
# Area = l * b
# print(f"{Area} is Area of a Rectangle")
# OUTPUT
# Enter the length of a Rectangle: 5
# Enter the breadth of a Rectangle: 2
# 10.0 is Area of a Rectangle

5.Write a program to calculate area and perimeter of the square


s=int(input("Enter Side : "))
area=s*s perimeter=4*s
print(f"{area} is Area of Rectangle ") print(f"{perimeter}
is Perimeter of Rectangle")
# OUTPUT
# Enter Side : 5
# 25 is Area of Rectangle
# 20 is Perimeter of Rectangle

6.Write a program to calculate surface volume and area of a cylinder.


pi= 3.14 radius = float(input('Please Enter the Radius of a
Cylinder: ')) height = float(input('Please Enter the Height of a
Cylinder: ')) sa = 2 * pi * radius * (radius + height) Volume
= pi * radius * radius * height print(f"{sa} is Surface area of
a Cylinder")
print(f"{Volume} is Volume of a Cylinder")
#OUTPUT
# Please Enter the Radius of a Cylinder: 5
# Please Enter the Height of a Cylinder: 5
# 314.0is Surface area of a Cylinder
# 392.5is Volume of a Cylinder

7.Write a program to swap the value of two variables x


= int(input("Enter the First No")) y = int(input("Enter
the First No"))
x, y = y, x print ("After swapping: ")
print("Value of x : ", x, " and y : ", y)
# OUTPUT
# After swapping:
# Value of x : 3 and y:3
PRACTICAL NO 3
1. Print the following patterns using loop:
A)
n=int(input("enter the no "))
i=1;j=0 while(i<=n):
while(j<=i-1): print("*
",end="") j+=1
print("\r")
j=0;i+=1 #
enter the no 4
#*#**#***#****

B) rows = 2 k = 2 * rows -
2 for i in range(0, rows):
for j in range(0, k):
print(end=" ") k = k - 1 for
j in range(0, i + 1):
print("* ", end="")
print("") k = rows - 2 for i
in range(rows, -1, -1): for j
in range(k, 0, -1):
print(end=" ") k = k +
1 for j in range(0, i +
1): print("* ", end="")
print("")
#OUTPUT # * # * * # * * * # * * # *

C) n=int(input("Enter the number


")) for i in range(n, 0, -2): for j in
range((n-i) // 2):
print(" ", end="")
for j in range(i):
if j % 2 == 0:
print(1, end="")
else: print(0,
end="")
print()
# Enter the number 9
# 101010101 # 1010101 # 10101 # 101 # 1
2)Write a Python program to print all even numbers between 1 to 100 using while
loop. num = 2 while num <= 100: print(num)
num = num + 2
# OUTPUT # 2 # 4 # 6 # 8 # 10 .... 100

3)Write a Python program to find the sum of first 10 natural numbers using for loop.
n=10 sum1
= 0 while(n
> 0):
sum1=sum1+n n=n-1
print(f"{sum1} is The sum of first 10 natural numbers")
# OUTPUT # 55 is The sum of first 10 natural
numbers

2.Write a Python program to print Fibonacci series. n_terms =


int(input ("How many terms the user wants to print? ")) n_1 = 0 n_2
= 1 count = 0 if n_terms == 1: print ("The Fibonacci sequence of
the numbers up to", n_terms, ": ") print(n_1) else:
print ("The fibonacci sequence of the numbers is:")
while count < n_terms: print(n_1) nth = n_1 + n_2
n_1 = n_2 n_2 = nth count += 1
# OUTPUT
# How many terms the user wants to print? 5 #
The fibonacci sequence of the numbers is:
#0#1#1#2#3

3.Write a Python program to calculate factorial of a number num =


int(input("Enter a number: "))
factorial = 1 if
num == 0:
print("The factorial of 0 is 1")
else: for i in range(1,num +
1): factorial = factorial*i
print("The factorial of",num,"is",factorial)
# OUTPUT # Enter a number: 6 # The
factorial of 6 is 720

4.Write a Python Program to Reverse a Given Number n


= 4562 rev = 0 while(n > 0): a = n % 10
rev = rev * 10 + a n = n // 10
print(rev)
# OUTPUT # 2654

5.Write a Python program takes in a number and finds the sum of digits in a number.
n=int(input("Enter a number:")) total=0 while(n>0): digit=n%10 total=total+digit
n=n//10
print("The total sum of digits is:",total)
# OUTPUT # Enter a number:23 # The total
sum of digits is: 5

6.Write a Python program that takes a number and checks whether it is a palindrome
or not.
number = int(input("Enter the number: "))
temp = number reverse =0 while
(number > 0): dig = number % 10
reverse = reverse * 10 + dig number =
number // 10
print("The reverse number is: ", reverse)
if temp==reverse:
print("The number is a palindrome") else:
print("The number is not a palindrome")
# OUTPUT # Enter the number: 231 # The
reverse number is: 132 # The number is not a
palindrome

7.Write a program to check whether a number is even or odd n


= int(input("Enter the number: ")) if n%2==0:
print("f{n} is a even number") else:
print(f"{n} is a odd number")
# OUTPUT
# Enter the number: 23 # 23 is a odd number
8.Write a program to find out absolute value of an input number
a=int(input("Enter the number")) if a >= 0: print(a) else: print(-a)
# OUTPUT # Enter the number-9 # 9

9.Write a program to check the largest number among the three numbers
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)
# OUTPUT # Enter first number: 25 # Enter
second number: 36 # Enter third number: 10 #
The largest number is 36.0

10.Write a program to check if the input year is a leap year of not


# Python program to check leap year or not
def checkYear(year): if (year % 4) == 0: if
(year % 100) == 0: if (year % 400) == 0:
return True else:
return False else:
return True else:
return False year =
int(input("Enter the year"))
if(checkYear(year)): print("Leap
Year") else:
print("Not a Leap Year")
#OUPUT #Enter the year 2004 #Leap Year

11.Write a program to check if a Number is Positive, Negative or Zero


n=int(input("Enter a number ")) if n>0:
print("the number is positive") elif
n<0:
print("the number is negative") else:
print("the number is zero")
#OUTPUT # Enter a number 15 # the number
is positive
12. Write a program that takes the marks of 5 subjects and displays the grade.
sub1=float(input("Enter marks of the first subject: "))

sub2=float(input("Enter marks of the second subject: "))


sub3=float(input("Enter marks of the third subject: ")) sub4=float(input("Enter
marks of the fourth subject: ")) sub5=float(input("Enter marks of the fifth
subject: "))
avg=(sub1+sub2+sub3+sub4+sub4)/5 if(avg>=90):
print("Grade: A") elif(avg>=80
and avg<90):
print("Grade: B") elif(avg>=70
and avg<80):
print("Grade: C")
elif(avg>=60 and avg<70):
print("Grade: D") else:
print("Grade: F")
# OUTPUT
# Enter marks of the first subject: 54
# Enter marks of the second subject: 46
# Enter marks of the third subject: 32
# Enter marks of the fourth subject: 15
# Enter marks of the fifth subject: 21
# Grade: F
PRACTICAL NO 4

1. Write a Python program to sum all the items in a


list. l=[34, 56 , 78, 86] total=0 for i in l: total=total+i
print(total)
# OUTPUT
# 254

2. Write a Python program to multiply all the items in a


list. l=[34, 56 , 78, 86] total=1 for i in l: total*=i
print(total)
# OUTPUT # 12772032

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


l=[34, 56 , 78, 86]
m= l[ 0 ] for a in
l: if a > m: m = a
print("max num in list is",m)
# OUTPUT
# max num in list is 86

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


list. l=[34, 56 , 78, 86] m= l[ 0 ] for a in l: if a < m: m = a
print("smallest num in list is",m)
# OUTPUT
# smallest num in list is 34

5. Write a Python program to reverse a list. l=[34, 56 , 78, 86] L = len(l) for i in
range(int(L/2)): n = l[i] l[i] = l[L-i-1] l[L-i-1] = n print(l)
# OUTPUT # [86, 78, 56, 34]
# Write a Python program to find common items from two lists.
l1 = [5, 10, 15, 20, 25, 30] l2= [10,
20, 30, 40, 50, 60] common_list = [c
for c in l1 if c in l2]
print(common_list)
# OUTPUT # [10, 20, 30]

PRACTICAL NO 5
1.create a tuple and find min and max num from it
# Smallest t1=[2, 5, 6, 6, 7, 8, 9]
s=t1[0] for i in range(len(t1)): if
(s>t1[i]): s=t1[i] print("the
smallest element is",s)
# the smallest element is 2

# Largest t2=[2, 5, 6, 6, 7, 8, 9]
s=t2[0] for i in range(len(t2)): if
(s<t2[i]): s=t2[i] print("the
Largest element is",s)
# the Largest element is 9

2.Write a python program to find repeated items of a tuple


# t = [int(x) for x in input("Enter any value:").split()]
# t = tuple(t) t=[2, 5, 6, 6, 7,
8, 9] print("Repeated
Values is:") for i in
range(0,len(t)): for j in
range(i+1,len(t)): if
t[i]==t[j]: print(t[i])
# OUTPUT
# Repeated Values is:
#6

3.Print the number in words


def Value(no): if no=='1':
print("One") elif no =='2':
print("Two") elif no =='3':
print("Three") elif no =='4':
print("Four") def word(n):
i=0 length=len(n) while
i<length: Value(n[i]) i+=1
n="1234" word(n)
#OUPUT #One #Two #Three #Four

You might also like