Programming With Python

Programming With Python Practical 16

Programming With Python Practical 16 Question 1 Write a Python program to Check for ZeroDivisionError Exception. division.py num1=int(input("Enter a numerator: ")) num2=int(input("Enter a denominator: ")) try: result=num1/num2 print("Division is: ",result) except ZeroDivisionError: print("Denominator can not be zero") Output Question 2 Write a Python program to create user defined exception that will check whether the password […]

Programming With Python Practical 16 Read More »

Programming With Python Practical 15

Programming With Python Practical 15 Question 1 Create a class Employee with data members: name, department and salary. Create suitable methods for reading and printing employee information emp.py class Person: name="" def getData(self,n): self.name=n def putData(self): print("Name is: ",self.name) class Employee(Person): department="" salary=None def get(self,dep,sal): self.department=dep self.salary=sal def put(self): print("Department is: ",self.department) print("Salary is: ",

Programming With Python Practical 15 Read More »

Programming With Python Practical 13

Programming With Python Practical 13 Question 1 Write a Python program to create two matrices and perform addition, subtraction, multiplication and division operation on matrix. matrix.py import numpy as np a=np.array([]) b=np.array([]) print("Enter elements of first matrix: ") for i in range(0,4): num=int(input("Element:")) a=np.append(a,num) a.shape=(2,2) print("Enter elements of second matrix: ") for i in range(0,4):

Programming With Python Practical 13 Read More »

Programming With Python Practical 12

Programming With Python Practical 12 Question 1 Write a Python program to create a user defined module that will ask your college name and will display the name of the college. college.py def getcollege(): cname=input("Enter your college name: ") print("Your college name is: ",cname) collegemain.py import college college.getcollege() Output Question 2 Write a Python program

Programming With Python Practical 12 Read More »

Programming With Python Practical 11

Programming With Python Practical 11 Question 1 Write a Python function that takes a number as a parameter and check the number is prime or not. prime.py def primeno(num): flag=0 for i in range(2,num): if(num%i==0): flag=1 break if(flag==1): print("number is not prime") else: print("number is prime") num=int(input("Enter a number")) primeno(num) Output Question 2 Write a

Programming With Python Practical 11 Read More »

Programming With Python Practical 10

Programming With Python Practical 10 Question 1 Write a Python function that accepts a string and calculate the number of upper case letters and lower case letters. count.py Str=input("Enter a string: ") count1=0 count2=0 for i in Str: if(i.islower()): count1+=1 else: count2+=1 print("The number of lowercase letters is: ",count1) print("The number of uppercase letters is:

Programming With Python Practical 10 Read More »

Programming With Python Practical 9

Programming With Python Practical 9 Question 1 Write a Python script to sort (ascending and descending) a dictionary by value. sort.py my_dict = { 'num1': 6, 'num2': 3, 'num3': 2, 'num4': 4, 'num5': 1, 'num6': 5} sortedVal = sorted(my_dict.values()) keys=[] print("Dictionary in ascending order by values is: ") for val in sortedVal: for k,v in

Programming With Python Practical 9 Read More »

Programming With Python Practical 8

Programming With Python Practical 8 Question 1 Write a Python program to create a set, add member(s) in a set and remove one item from set. createset.py num={10,50,60,40,20,30,80} print("Set is created as :",num) a=int(input("Enter the number to add into set :")) num.add(a) print("After adding set is :",num) b=int(input("Enter the number to remove from set :"))

Programming With Python Practical 8 Read More »

Programming With Python Practical 7

Programming With Python Practical 7 Question 1 Create a tuple and find the minimum and maximum number from it. minmax.py tup=(1,2,3,5,56,9,8,6,4) largest=tup[0] smallest=tup[0] for i in tup: if(i>largest): largest=i for i in tup: if(i<smallest): smallest=i print("Largest number is :",largest) print("Smallest number is :",smallest) Output Question 2 Write a Python program to find the repeated items

Programming With Python Practical 7 Read More »