PSSP Lab Manual
1.Write a program to demonstrate different number data types in python.
Program :
a=10;
b=11.3;
c=20.7;
print("a is Type of",type(a));
print("b is Type of",type(b));
print("c is Type of",type(c));
2. Write a program to perform different arithmetic operations on numbers in python.
Program :
a=int(input("Enter a value: "));
b=int(input("Enter b value: "));
print("Addition of a and b ",a+b);
print("Subtraction of a and b ",a-b);
print("Multiplication of a and b ",a*b);
print("Division of a and b ",a/b);
print("Remainder of a and b ",a%b);
print("Exponent of a and b ",a**b);
print("Floar division of a and b ",a//b);
3. Write a program to create, concatenate and print a string and accessing substring
from a given string.
Program :
s1=input("Enter first String : ");
s2=input("Enter second String : ");
print("First string is : ",s1);
print("Second string is : ",s2);
print("concatenations of two strings :",s1+s2);
print("Substring of given string :",s1[1:4]);
4. Write a python script to print the current date in following format “Sun May 29
02:26:23 IST 2017”.
Program :
import time;
ltime=time.localtime();
print(time.strftime("%a %b %d %H:%M:%S %Z %Y",ltime));
'''
%a : Abbreviated weekday name.
%b : Abbreviated month name.
%d : Day of the month as a decimal number [01,31].
%H : Hour (24-hour clock) as a decimal number [00,23].
%M : Minute as a decimal number [00,59].
%S : Second as a decimal number [00,61].
%Z : Time zone name (no characters if no time zone exists).
%Y : Year with century as a decimal number.'''
5.Write a python program to create, append and remove lists in python.
Program :
class check():
def __init__(self):
self.n=[]
def add(self,a):
return self.n.append(a)
def remove(self,b):
self.n.remove(b)
def dis(self):
return (self.n)
obj=check()
choice=1
while choice!=0:
print("0. Exit")
print("1. Add")
print("2. Delete")
print("3. Display")
choice=int(input("Enter choice: "))
if choice==1:
n=int(input("Enter number to append: "))
obj.add(n)
print("List: ",obj.dis())
elif choice==2:
n=int(input("Enter number to remove: "))
obj.remove(n)
print("List: ",obj.dis())
elif choice==3:
print("List: ",obj.dis())
elif choice==0:
print("Exiting!")
else:
print("Invalid choice!!")
print()
6. Write a program to demonstrate working with tuples in python.
Program :
T = ("apple", "banana", "cherry","mango","grape","orange")
print("\n Created tuple is :",T)
print("\n Second fruit is :",T[1])
print("\n From 3-6 fruits are :",T[3:6])
print("\n List of all items in Tuple :")
for x in T:
print(x)
if "apple" in T:
print("\n Yes, 'apple' is in the fruits tuple")
print("\n Length of Tuple is :",len(T))
7.Write a program to demonstrate working with dictionaries in python.
dict1 = {'StdNo':'532','StuName': 'Naveen', 'StuAge': 21, 'StuCity': 'Hyderabad'}
print("\n Dictionary is :",dict1)
#Accessing specific values
print("\n Student Name is :",dict1['StuName'])
print("\n Student City is :",dict1['StuCity'])
#Display all Keys
print("\n All Keys in Dictionary ")
for x in dict1:
print(x)
#Display all values
print("\n All Values in Dictionary ")
for x in dict1:
print(dict1[x])
#Adding items
dict1["Phno"]=85457854
#Updated dictoinary
print("\n Uadated Dictionary is :",dict1)
#Change values
dict1["StuName"]="Madhu"
#Updated dictoinary
print("\n Updated Dictionary is :",dict1)
#Removing Items
dict1.pop("StuAge");
#Updated dictoinary
print("\n Updated Dictionary is :",dict1)
#Length of Dictionary
print("Length of Dictionary is :",len(dict1))
#Copy a Dictionary
dict2=dict1.copy()
#New dictoinary
print("\n New Dictionary is :",dict2)
#empties the dictionary
dict1.clear()
print("\n Updated Dictionary is :",dict1)
8.Write a python program to find largest of three numbers.
Program :
a=5
b=4
c=7
largest = 0
if a > b and a > c:
largest = a
if b > a and b > c:
largest = b
if c > a and c > b:
largest = c
print(largest, "is the largest of three numbers.")
9.Write a python program to convert temperature to and from Celsius to Fahrenheit.
Program :
celsius = 47
fahrenheit = (celsius * 1.8) + 32
print('%.2f Celsius is equivalent to: %.2f Fahrenheit'
% (celsius, fahrenheit))
10. Write a python program to construct the following pattern using nested for loop:
*
**
***
****
*****
****
***
**
*
Program :
n=5;
for i in range(n):
for j in range(i):
print ('* ', end="")
print('')
for i in range(n,0,-1):
for j in range(i):
print('* ', end="")
print('')